static void Main() { int n = int.Parse(Console.ReadLine()); int[][] a = new int[n][]; int[][] b = new int[n][]; long ans = 0, ih = 1; for (int i = 0; i < n; i++) { int[] q = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); a[i] = new int[] { q[0], i }; b[i] = new int[] { q[1], i }; } Array.Sort(a, (u, v) => u[0] - v[0]); Array.Sort(b, (u, v) => u[0] - v[0]); for (int i = 0; i < n - 1; i++) { heapa(a[i + 1][0] - a[i][0], a[i][1], a[i + 1][1]); heapa(b[i + 1][0] - b[i][0], b[i][1], b[i + 1][1]); } uf t = new uf(n); while (ih != n) { if (!t.same(he[0][1], he[0][2])) { t.union(he[0][1], he[0][2]); ans += he[0][0]; ih++; } heapr(); } Console.WriteLine("{0}", ans); }
public List <uf> PreencherUfs() { uf estados = new uf(); estados.ListaEstados.Add(new uf() { sigla = "SP", nome = "São Paulo" }); estados.ListaEstados.Add(new uf() { sigla = "RJ", nome = "Rio de Janeiro" }); estados.ListaEstados.Add(new uf() { sigla = "SC", nome = "Santa Catarina" }); estados.ListaEstados.Add(new uf() { sigla = "GO", nome = "Goais" }); estados.ListaEstados.Add(new uf() { sigla = "MG", nome = "Minas Gerias" }); estados.ListaEstados.Add(new uf() { sigla = "MT", nome = "Mato Grosso" }); return(estados.ListaEstados); }
public ActionResult Index(uf ufs) { if (ModelState.IsValid) { ViewData["msg"] = "ok"; } return(View(ufs)); }
public void insert(uf uf) { using (var db = new ReservasModel1()) { db.ufs.Add(uf); db.SaveChanges(); } }
public ActionResult DeleteConfirmed(int id) { uf uf = db.uf.Find(id); db.uf.Remove(uf); db.SaveChanges(); return(RedirectToAction("Index")); }
public void update(uf uf) { using (var db = new ReservasModel1()) { db.ufs.Attach(uf); db.Entry(uf).Property(u => u.desc_uf).IsModified = true; db.SaveChanges(); } }
public ActionResult Index() { uf ufs = new uf(); ufs.uf_id = "PR"; ufs.desc_uf = "Parana"; return(View(ufs)); }
public ActionResult Edit([Bind(Include = "id_uf,sigla,nome,id_pais")] uf uf) { if (ModelState.IsValid) { db.Entry(uf).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.id_pais = new SelectList(db.pais, "id_pais", "nome", uf.id_pais); return(View(uf)); }
public ActionResult Create([Bind(Include = "id_uf,sigla,nome,id_pais")] uf uf) { if (ModelState.IsValid) { db.uf.Add(uf); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.id_pais = new SelectList(db.pais, "id_pais", "nome", uf.id_pais); return(View(uf)); }
// GET: uf/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } uf uf = db.uf.Find(id); if (uf == null) { return(HttpNotFound()); } return(View(uf)); }
// GET: uf/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } uf uf = db.uf.Find(id); if (uf == null) { return(HttpNotFound()); } ViewBag.id_pais = new SelectList(db.pais, "id_pais", "nome", uf.id_pais); return(View(uf)); }