# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
604436 | 2022-07-25T06:27:52 Z | temporary_juggernaut | Mergers (JOI19_mergers) | C++14 | 216 ms | 73532 KB |
#include<bits/stdc++.h> #define fr first #define sc second using namespace std; typedef long long ll; typedef long double ld; template<class T>void umax(T &a,T b){if(a<b)a=b;} template<class T>void umin(T &a,T b){if(b<a)a=b;} #ifdef juggernaut #define printl(args...) printf(args) #else #define printl(args...) 0 #endif int n,k; vector<int>g[500005]; int sz[500005]; int gp[500005]; set<int>st[500005]; int pivot[500005]; int sub[500005]; void add(int a,int b){ if(st[a].size()<st[b].size()){ swap(st[a],st[b]); swap(pivot[a],pivot[b]); } for(int to:st[b]){ if(!st[a].count(to)){ st[a].insert(to); pivot[a]+=sz[to]; } } st[b].clear(); } int tot; int sweet[500005]; map<int,int>mp[500005]; void dfs(int v,int p){ pivot[v]=sz[gp[v]]; sub[v]=1; st[v].insert(gp[v]); for(int to:g[v])if(to^p){ dfs(to,v); if(sub[to]==pivot[to]){ mp[v][to]=true; sweet[v]++; tot++; } sweet[v]+=sweet[to]; add(v,to); sub[v]+=sub[to]; } } int ans; void go(int v,int p){ for(int to:g[v])if(to^p){ go(to,v); if(mp[v][to]){ if(sweet[to]>0&&tot-sweet[v]>0){ ans--; } } } } int main(){ scanf("%d%d",&n,&k); for(int i=1;i^n;i++){ int x,y; scanf("%d%d",&x,&y); g[x].push_back(y); g[y].push_back(x); } for(int i=1;i<=n;i++){ scanf("%d",&gp[i]); sz[gp[i]]++; } dfs(1,1); ans=tot; go(1,1); cout<<max(0,ans-1); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 27 ms | 58968 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 27 ms | 58968 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 27 ms | 58968 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 133 ms | 68396 KB | Output is correct |
2 | Incorrect | 216 ms | 73532 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 27 ms | 58968 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |