# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
127617 | 2019-07-09T16:35:29 Z | wilwxk | Mergers (JOI19_mergers) | C++14 | 125 ms | 44152 KB |
#include <bits/stdc++.h> using namespace std; const int MAXN=5e5+5; vector<int> g[MAXN]; map<int, int> mp[MAXN]; int cor[MAXN], contc[MAXN]; int n, x, respf; int dfs(int cur, int p) { mp[cur][cor[cur]]++; int cont=0; for(auto viz : g[cur]) { if(viz==p) continue; cont+=dfs(viz, cur); if(mp[viz].size()>mp[cur].size()) swap(mp[cur], mp[viz]); for(auto mit : mp[viz]) { mp[cur][mit.first]+=mit.second; if(mp[cur][mit.first]==contc[mit.first]) mp[cur].erase(mit.first); } } if(mp[cur][cor[cur]]==contc[cor[cur]]) mp[cur].erase(cor[cur]); if(mp[cur].empty()) { if(cur!=0) cont++; if(cont==1) respf++; // printf("%d >> %d\n", cur, cont); } return cont>0; } int main() { scanf("%d %d", &n, &x); for(int i=1; i<n; i++) { int a, b; scanf("%d %d", &a, &b); g[a].push_back(b); g[b].push_back(a); } for(int i=1; i<=n; i++) { scanf("%d", &cor[i]); contc[cor[i]]++; } cor[0]=0; contc[0]=1; g[0].push_back(1); g[1].push_back(0); dfs(0, 0); if(n!=1) printf("%d\n", (respf+1)/2); else printf("0\n"); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 35576 KB | Output is correct |
2 | Incorrect | 34 ms | 35580 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 35576 KB | Output is correct |
2 | Incorrect | 34 ms | 35580 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 35576 KB | Output is correct |
2 | Incorrect | 34 ms | 35580 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 125 ms | 44152 KB | Output is correct |
2 | Correct | 118 ms | 39792 KB | Output is correct |
3 | Incorrect | 37 ms | 35960 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 35576 KB | Output is correct |
2 | Incorrect | 34 ms | 35580 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |