static object Solve() { var(n, m) = Read2(); var es = Array.ConvertAll(new bool[m], _ => Read2()); var uf = new UF(n + 1); foreach (var e in es) { uf.Unite(e.u, e.v); } var eCounts = new int[n + 1]; foreach (var e in es) { eCounts[uf.GetRoot(e.u)]++; } var roots = Enumerable.Range(1, n).Select(uf.GetRoot).Distinct().ToArray(); if (roots.Any(p => uf.GetSize(p) != eCounts[p])) { return(0); } return(MPow(2, roots.Length)); }
public KruskalMST(EdgeWeightedGraph ewg) { this.mst = new Queue(); MinPQ minPQ = new MinPQ(); Iterator iterator = ewg.edges().iterator(); while (iterator.hasNext()) { Edge edge = (Edge)iterator.next(); minPQ.insert(edge); } UF uF = new UF(ewg.V()); while (!minPQ.isEmpty() && this.mst.size() < ewg.V() - 1) { Edge edge = (Edge)minPQ.delMin(); int num = edge.either(); int i = edge.other(num); if (!uF.connected(num, i)) { uF.union(num, i); this.mst.enqueue(edge); this.weight += edge.weight(); } } if (!KruskalMST.s_assertionsDisabled && !this.check(ewg)) { throw new AssertionError(); } }
static void Main() { var h = Read(); var n = h[0]; var ab = new int[h[1]].Select(_ => Read()).ToArray(); var cd = new int[h[2]].Select(_ => Read()).ToArray(); var uf = new UF(n + 1); foreach (var x in ab) { uf.Unite(x[0], x[1]); } var roots = Enumerable.Range(0, n + 1).GroupBy(uf.GetRoot).ToDictionary(g => g.Key, g => g.Count()); var c = Enumerable.Range(0, n + 1).Select(uf.GetRoot).Select(x => roots[x] - 1).ToArray(); foreach (var x in ab) { c[x[0]]--; c[x[1]]--; } foreach (var x in cd) { if (!uf.AreUnited(x[0], x[1])) { continue; } c[x[0]]--; c[x[1]]--; } Console.WriteLine(string.Join(" ", c.Skip(1))); }
public async Task <List <Pessoa> > BuscarPorUF(UF uf) { var pessoas = new List <Pessoa>(); pessoas.Where(p => p.UF == uf).ToList(); return(pessoas); }
private Queue <Edge> mst = new Queue <Edge>(); // edges in MST public KruskalMST(EdgeWeightedGraph G) { // more efficient to build heap by passing array of edges EdgeComparer comparer = new EdgeComparer(); MinPQ <Edge> pq = new MinPQ <Edge>((Comparer <Edge>)comparer); foreach (Edge e in G.edges()) { pq.insert(e); } // run greedy algorithm UF uf = new UF(G.V()); while (!pq.isEmpty() && mst.size() < G.V() - 1) { Edge e = pq.delMin(); int v = e.either(); int w = e.other(v); if (!uf.connected(v, w)) { // v-w does not create a cycle uf.union(v, w); // merge v and w components mst.Enqueue(e); // add edge e to mst weight += e.Weight(); } } }
private readonly Collections.Queue <EdgeW> _mst = new Collections.Queue <EdgeW>(); // edges in MST /// <summary> /// Compute a minimum spanning tree (or forest) of an edge-weighted graph. /// </summary> /// <param name="g">g the edge-weighted graph</param> public KruskalMST(EdgeWeightedGraph g) { // more efficient to build heap by passing array of edges var pq = new MinPQ <EdgeW>(); foreach (var e in g.Edges()) { pq.Insert(e); } // run greedy algorithm var uf = new UF(g.V); while (!pq.IsEmpty() && _mst.Size() < g.V - 1) { var e = pq.DelMin(); var v = e.Either(); var w = e.Other(v); if (!uf.Connected(v, w)) { // v-w does not create a cycle uf.Union(v, w); // merge v and w components _mst.Enqueue(e); // add edge e to mst _weight += e.Weight; } } // check optimality conditions //assert check(G); }
public FormUF(UF uf) { InitializeComponent(); txtId.Text = uf.Id.ToString(); txtNome.Text = uf.Nome; txtSigla.Text = uf.Sigla; }
//Construtores public Pessoas_e_Empresas(int id, bool clienteBloqueado, bool cliente, bool pessoaFisica, bool pessoaJuridica, bool fornecedor, bool funcionario, DateTime dataDeCadastro, Status status, bool nomeSocial, string nomeRazaoSocial, string apelidoNomeFantasia, string cPFCNPJ, Indicador_da_IE_do_Destinatário indicadorDaIEDoDestinatario, string rGInscricaoEstadual, string inscricaoMunicipal, string emissorDoRG, UF uFDoEmissor, Sexo sexo, DateTime aniversario, string telefone, string celular, string email, string emailParaNFE, string site, string observacao, decimal limiteDeCredito, bool issRetidoNaFonte, bool consumidorFinal, bool produtorRural, bool serasa) { Id = id; ClienteBloqueado = clienteBloqueado; Cliente = cliente; PessoaFisica = pessoaFisica; PessoaJuridica = pessoaJuridica; Fornecedor = fornecedor; Funcionario = funcionario; DataDeCadastro = dataDeCadastro; Status = status; NomeSocial = nomeSocial; NomeRazaoSocial = nomeRazaoSocial; ApelidoNomeFantasia = apelidoNomeFantasia; CPFCNPJ = cPFCNPJ; IndicadorDaIEDoDestinatario = indicadorDaIEDoDestinatario; RGInscricaoEstadual = rGInscricaoEstadual; InscricaoMunicipal = inscricaoMunicipal; EmissorDoRG = emissorDoRG; UFDoEmissor = uFDoEmissor; Sexo = sexo; Aniversario = aniversario; Telefone = telefone; Celular = celular; Email = email; EmailParaNFE = emailParaNFE; Site = site; Observacao = observacao; LimiteDeCredito = limiteDeCredito; IssRetidoNaFonte = issRetidoNaFonte; ConsumidorFinal = consumidorFinal; ProdutorRural = produtorRural; Serasa = serasa; }
static void Main() { var(l, qc) = Read2(); var qs = Array.ConvertAll(new bool[qc], _ => Read2()); Array.Reverse(qs); var seps = qs.Where(q => q.c == 1).Select(q => q.x).Prepend(0).Append(l).ToArray(); Array.Sort(seps); var map = ToInverseMap(seps); var r = new List <int>(); var uf = new UF <int>(seps.Length, (x, y) => x + y, Enumerable.Range(0, seps.Length - 1).Select(i => seps[i + 1] - seps[i]).ToArray()); foreach (var(c, x) in qs) { if (c == 1) { uf.Unite(map[x] - 1, map[x]); } else { var i = Last(-1, seps.Length - 1, xi => seps[xi] <= x); r.Add(uf.GetValue(i)); } } r.Reverse(); Console.WriteLine(string.Join("\n", r)); }
private IEnumerable <Endereco> BuscarSemCache(UF UF, string cidade, string logradouro) { var url = ControleDeUrl.GerarURLDaPesquisa(UF, cidade, logradouro); var strJSON = Requisicoes.ObterJSON(url); return(JsonConvert.DeserializeObject <List <Endereco> >(strJSON)); }
static bool Solve() { var(n, m) = Read2(); var es = Array.ConvertAll(new bool[m], _ => Read2()); var u = new int[n + 1]; var uf = new UF(n + 1); foreach (var(a, b) in es) { if (++u[a] > 2) { return(false); } if (++u[b] > 2) { return(false); } if (!uf.Unite(a, b)) { return(false); } } return(true); }
public ActionResult DeleteConfirmed(int id) { UF query = this.Repositorio.Obter(id); this.Repositorio.Excluir(query); return(RedirectToAction("Index")); }
private IEnumerable <Endereco> BuscarSemCache(UF uf, string cidade, string logradouro) { var url = ControleDeUrl.GerarUrlDaPesquisa(uf, cidade, logradouro); var json = Requisicoes.ObterJson(url); return(JsonConvert.DeserializeObject <List <Endereco> >(json)); }
static long mst() { long weight = 0; Array.Sort(edges); UF cities = new UF(M); UF planets = new UF(N); for (int i = 0; i < edges.Length && (cities.cnt > 1 || planets.cnt > 1); i++) { Edge e = edges[i]; if (e.type) { if (planets.join(e.a, e.b)) { weight += cities.cnt * e.c; } } else { if (cities.join(e.a, e.b)) { weight += planets.cnt * e.c; } } } return(weight); }
public EstadoDestino() { AddNotifications(new Contract() .Requires() .Matchs(UF.ToString(), _match, "EstadoDestino.UF", "") ); }
public void Excluir(UF uf) { var parametros = new Dictionary <string, object>(); parametros.Add("Id", uf.Id); ExecuteScalar(CmdDelete, parametros); }
public ActionResult RealizarCadastro(Paciente p) { try { if (ModelState.IsValid) { p.Cadastrar(p, ObterCodigoClinicaUsuarioLogado()); TempData["MsgSucesso"] = "Paciente cadastrado com sucesso."; return(RedirectToAction("Detalhe", "Prontuario", new { Codigo = p.Codigo })); } else { UF UF = new UF(); ViewBag.UFS = new SelectList(UF.ObterRegistros().ToList(), "Codigo", "Sigla"); List <Cidade> Cidades = new List <Cidade>(); ViewBag.Cidades = new SelectList(Cidades, "Codigo", "Descricao"); return(View("Cadastro")); } } catch (Exception e) { TempData["MsgErro"] = e.Message; return(RedirectToAction("Index", "Prontuario")); } }
public void UFTest1() { // no connected components Tuple <int, int>[] set1 = { new Tuple <int, int>(1, 1), new Tuple <int, int>(2, 2), new Tuple <int, int>(3, 3), new Tuple <int, int>(0, 0) }; UF uf = Union(set1, set1.Length); Assert.AreEqual(uf.Count, set1.Length); // three connected components Tuple <int, int>[] set2 = { new Tuple <int, int>(0, 1), new Tuple <int, int>(2, 3), new Tuple <int, int>(4, 5), new Tuple <int, int>(6, 0), new Tuple <int, int>(7, 1) }; uf = Union(set2, 8); Assert.AreEqual(uf.Count, 3); set2[0] = new Tuple <int, int>(7, 8); uf = Union(set2, 8); // generate exception }
static void Main() { Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var h = Read(); int n = h[0], qc = h[1]; var qs = Array.ConvertAll(new bool[qc], _ => Read()); var uf = new UF(n); foreach (var q in qs) { if (q[0] == 0) { uf.Unite(q[1], q[2]); } else { Console.WriteLine(uf.AreUnited(q[1], q[2]) ? 1 : 0); } } Console.Out.Flush(); }
//public Dictionary<UF, decimal> ValoresFrete { get; set; } *DICTIONARY, USA UMA 1 CHAVE(KEY) E 2 UM VALUE //public void PreecherValores() //{ // ValoresFrete.Add(UF.SP, 0.2M); // ValoresFrete.Add(UF.RJ, 0.3M); // *CRIANDO UM DICTIONARY // ValorFrete = ValoresFrete[UF]; *UMA OUTRA MANEIRA, SEM FAZER SWITCH //} private void Calcular() { switch (UF.ToString().ToUpper()) { case "SP": ValorFrete = 0.2m; break; case "RJ": ValorFrete = 0.3m; break; case "MG": ValorFrete = 0.35m; break; case "AM": ValorFrete = 0.6m; break; default: ValorFrete = 0.7m; break; } ValorTotal = (1 + ValorFrete) * ValorProduto; }
public void Uf_of_5_of_april_is_10782_09() { scraper.Extract(); UF uf5OfApril = (UF)scraper.UFs.Where(it => it.Date == new DateTime(1994, 4, 5)).FirstOrDefault(); Assert.That(uf5OfApril.Value, Is.EqualTo(10782.09m)); }
public Frete(UF uf, decimal valorProduto) { UF = uf; ValorProduto = valorProduto; Calcular(); }
protected void ValidateUF(Expression <Func <T, string> > ufField) { RuleFor(ufField).Cascade(CascadeMode.StopOnFirstFailure) .NotNull().WithMessage("UF was not provided.") .NotEmpty().WithMessage("UF was not provided.") .Must(uf => UF.IsUF(uf)).WithMessage("Invalid UF"); }
/// <summary> /// Usado para cadastrar um usuário. /// </summary> /// <param name="email">Representa o email do usuário.</param> /// <param name="senha">Representa a senha do usuário.</param> public void CadastraUsuario(string crm, string nome, UF uF, string profissao, string email, string senha) { VerificaSeCRMEhCadastrado(crm); VerificaSeEmailEhCadastrado(email); this.EntidadeContext.Medicos.Add(new Medico(crm, nome, uF, profissao, new Usuario(email, senha))); this.EntidadeContext.SaveChanges(); }
private void CD_Clifor_Leave(object sender, EventArgs e) { FormBusca.UtilPesquisa.EDIT_LeaveClifor("a.cd_clifor|=|'" + CD_Clifor.Text.Trim() + "'", new Componentes.EditDefault[] { CD_Clifor, NM_Clifor }, new CamadaDados.Financeiro.Cadastros.TCD_CadClifor()); if (!string.IsNullOrEmpty(CD_Clifor.Text)) { //Buscar endereco this.BuscarEndereco(); NM_Clifor.Enabled = false; CD_Endereco.Enabled = true; BB_Endereco.Enabled = true; DS_Endereco.Enabled = false; DS_Cidade.Enabled = false; UF.Enabled = false; Fone.Enabled = false; } else { NM_Clifor.Enabled = true; CD_Endereco.Enabled = false; BB_Endereco.Enabled = false; DS_Endereco.Enabled = true; DS_Cidade.Enabled = true; UF.Enabled = true; Fone.Enabled = true; CD_Endereco.Clear(); DS_Endereco.Clear(); DS_Cidade.Clear(); UF.Clear(); Fone.Clear(); } }
static object Solve() { var n = int.Parse(Console.ReadLine()); var a = Read(); var d = TallyIndexes(a, max); var uf = new UF(n); for (int x = 0; x <= max; x++) { var l = d[x]; for (int i = 1; i < l.Count; i++) { uf.Unite(l[i - 1], l[i]); } } var r = 0; for (int i = 0; i < n; i++) { if (uf.Unite(i, n - 1 - i)) { r++; } } return(r); }
private void BB_Clifor_Click(object sender, EventArgs e) { FormBusca.UtilPesquisa.BTN_BuscaClifor(new Componentes.EditDefault[] { CD_Clifor, NM_Clifor }, string.Empty); if (!string.IsNullOrEmpty(CD_Clifor.Text)) { //Buscar endereco this.BuscarEndereco(); NM_Clifor.Enabled = false; CD_Endereco.Enabled = true; BB_Endereco.Enabled = true; DS_Endereco.Enabled = false; DS_Cidade.Enabled = false; UF.Enabled = false; Fone.Enabled = false; } else { NM_Clifor.Enabled = true; CD_Endereco.Enabled = false; BB_Endereco.Enabled = false; DS_Endereco.Enabled = true; DS_Cidade.Enabled = true; UF.Enabled = true; Fone.Enabled = true; CD_Endereco.Clear(); DS_Endereco.Clear(); DS_Cidade.Clear(); UF.Clear(); Fone.Clear(); } }
static void Main() { Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var h = Read(); int n = h[0], qc = h[1]; var c = Read(); var qs = Array.ConvertAll(new bool[qc], _ => Read()); var iv = c.Prepend(0).Select(ci => new Dictionary <int, int> { { ci, 1 } }).ToArray(); var uf = new UF <Dictionary <int, int> >(n + 1, CollectionHelper.Merge, iv); foreach (var q in qs) { if (q[0] == 1) { uf.Unite(q[1], q[2]); } else { Console.WriteLine(uf.GetValue(q[1]).GetValue(q[2])); } } Console.Out.Flush(); }
static void Main() { Func <int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray(); var h = read(); var ps = new int[h[0]].Select(_ => read()).ToArray(); var cs = new int[h[1]].Select(_ => read()).ToArray(); var uf = new UF(h[0]); foreach (var c in cs) { uf.Unite(c[0] - 1, c[1] - 1); } ps = uf.ToGroups().Select(g => new[] { g.Sum(x => ps[x][0]), g.Sum(x => ps[x][1]) }).ToArray(); var v = Enumerable.Repeat(-1, h[2] + 1).ToArray(); v[0] = 0; foreach (var p in ps) { for (int i = v.Length - 1; i >= 0; i--) { if (v[i] != -1 && i + p[0] < v.Length) { v[i + p[0]] = Math.Max(v[i + p[0]], v[i] + p[1]); } } } Console.WriteLine(v.Max()); }
static bool AreUnited(int n, int m, char[][] s, int ti, int tj) { var uf = new UF(n * m); int ToId(int x, int y) => x * m + y; for (int i = 0; i < n; i++) { for (int j = 1; j < m; j++) { if (s[i][j - 1] == '.' && s[i][j] == '.') { uf.Unite(ToId(i, j - 1), ToId(i, j)); } } } for (int j = 0; j < m; j++) { for (int i = 1; i < n; i++) { if (s[i - 1][j] == '.' && s[i][j] == '.') { uf.Unite(ToId(i - 1, j), ToId(i, j)); } } } var sum = s.Sum(r => r.Count(c => c == '.')); var root = uf.GetRoot(ToId(ti, tj)); return(Enumerable.Range(0, n * m).Count(v => uf.GetRoot(v) == root) == sum); }
public Endereco(string logradouro, int numero, string bairro, UF uf, string pais) { Logradouro = logradouro; Numero = numero; Bairro = bairro; UF = uf; Pais = pais; }
public Temperatura ObterTemperatura(UF uf) { Thread.Sleep(3000); var temp = new Temperatura { UF = uf }; switch (uf) { case UF.SP: temp.Temp = ObterRandom(30, 35); break; case UF.RJ: temp.Temp = ObterRandom(38, 42); break; case UF.MG: temp.Temp = ObterRandom(35, 40); break; case UF.AM: temp.Temp = ObterRandom(30, 40); break; } return temp; }
public Populacao ObterTotalPopulacaoPorUF(UF uf) { Thread.Sleep(3000); var populacao = new Populacao { UF = uf }; switch (uf) { case UF.SP: populacao.Qtde = 41252160; break; case UF.RJ: populacao.Qtde = 15993583; break; case UF.MG: populacao.Qtde = 19595309; break; case UF.AM: populacao.Qtde = 3480937; break; } return populacao; }
// This version is about 10% faster than recursive private unsafe int Find(UF* uf, int a) { Debug.Assert(IsInRange(a)); step* s = null; while (uf[a].Parent != a) { step* c = stackalloc step[1]; c->Element = a; c->Prev = s; s = c; a = uf[a].Parent; } while (s != null) { uf[s->Element].Parent = a; s = s->Prev; } return a; }
private unsafe int Find(UF* uf, int a) { Debug.Assert(IsInRange(a)); if (uf[a].Parent != a) uf[a].Parent = Find(uf[a].Parent); return uf[a].Parent; }
private unsafe int Find(UF* uf, int a) { Debug.Assert(IsInRange(a)); if(s_stack == null) s_stack = new Stack<int>(); while (uf[a].Parent != a) { s_stack.Push(a); a = uf[a].Parent; } while (s_stack.Count > 0) { int k = s_stack.Pop(); uf[k].Parent = a; } return a; }
/// <summary> /// Método utilizado para preencher esta instância com os dados do dataReader /// </summary> /// <param name="dataReader">DataReader com os dados que deverão ser passados para esta instância</param> public override void Populate(DataReader dataReader) { #region base base.Populate(dataReader); #endregion #region desta classe Nome = dataReader.GetValue<string>("p_Nome"); UF = dataReader.GetValue<string>("p_UF"); CodigoIBGE = dataReader.GetValue<string>("p_CodIBGE"); Pais = new Pais((OpenPOS.GUID)dataReader.GetValue<string>("p_GUIDPais")); #endregion }