upsolving
ps2020
grafo
const int N = 105;
vector<int> adj[N];
vector<string> v;
char s[N];
void compara(int a, int b) {
for(int i = 0; i < v[a].size() and i < v[b].size(); i++) {
if(v[a][i] != v[b][i]) {
adj[v[a][i]-'a'].pb(v[b][i]-'a');
return;
}
}
int main() {
for(int i = 1; i < v.size(); i++) {
compara(i-1, i);
}
}
Learn More →
Ideia:
Guloso: Se um nó u é uma cidade de negócio, todas as árvores em sua ramificação também será uma cidade de negócio.
//type here
priority_queue<int> pq;
int dfs(int u, int l){
if(vis[u])
return 0;
vis[u] = 1;
int filhos = 0;
for(int k : adj[u]){
filhos += dfs(k, l+1);
pq.push(l - filhos);
return filhos + 1;
}
Estrutura Básica: struct ListNode { int val; ListNode* next; ListNode() : val(0), next(nullptr) {} ListNode(int x) : val(x), next(nullptr) {} }; Visualizando...
Jul 11, 2020Trie Estrutura de dados Prefix Tree Cada aresta representa um símbolo do alfabeto Cada nó representa uma palavra, que corresponde a todas as arestas no caminho da raiz até o nó Lista de palavras: t
Jun 17, 2020{%hackmd theme-dark %} C #define pb push_back; #define all(x) x.begin(), x.end() bool prime[N] = {true}; void Sieve(int n){
Jun 11, 2020{%hackmd theme-dark %} Estruturas de dados Estrutura de dados é o ramo da computação que estuda os diversos mecanismos de organização de dados para atender aos diferentes requisitos de processamento. Exemplos: Pilha, Fila, Lista encadeada, Árvores binárias, Heap, DSU BIT, Segment tree, Treap, Sparse table
Jun 11, 2020or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up