# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
563799 | 2022-05-18T06:47:14 Z | dantoh000 | Mergers (JOI19_mergers) | C++14 | 123 ms | 41252 KB |
#include <bits/stdc++.h> using namespace std; int n,k; vector<int> G[1000005]; int c[1000005]; int low[1000005]; int num[1000005]; int p[1000005]; int sz[1000005]; int ct = 0; int ans = 0; int A[500005]; int B[500005]; void dfs(int u){ num[u] = low[u] = ct++; sz[u] = 1; for (auto v : G[u]){ if (num[v] == -1){ p[v] = u; //printf("%d -> %d\n",u,v); dfs(v); if (low[v] > num[u] && u <= n && v <= n){ //printf("%d %d\n",u,v); if (A[v] == 0){ A[v] = 1; } } low[u] = min(low[v], low[u]); } else if (v != p[u]){ low[u] = min(num[v], low[u]); } } } void dfs2(int u, int p){ for (auto v : G[u]){ if (v == p) continue; if (v > n) continue; dfs2(v, u); B[u] |= B[v]; } if (B[u] == 0 && A[u] == 1){ ans++; B[u] = 1; } } int main(){ scanf("%d%d",&n,&k); 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",&c[i]); G[i].push_back(n+c[i]); G[n+c[i]].push_back(i); } memset(low,-1,sizeof(low)); memset(num,-1,sizeof(num)); dfs(1); dfs2(1, -1); if (ans == 0) printf("0"); else printf("%d",max(ans-1,1)); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 31712 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 31712 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 31712 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 90 ms | 37236 KB | Output is correct |
2 | Incorrect | 123 ms | 41252 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 31712 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |