# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
563818 | 2022-05-18T07:16:34 Z | dantoh000 | Mergers (JOI19_mergers) | C++14 | 71 ms | 37952 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 pa[500005]; int eg[500005]; int rk[500005]; void init(int n){ for (int i = 1; i <= n; i++){ pa[i] = i; rk[i] = 0; eg[i] = 0; } } int fin(int x){ return pa[x] == x ? x : p[x] = fin(p[x]); } void un(int x, int y){ x = fin(x), y = fin(y); if (x == y) return; if (rk[x] < rk[y]) swap(rk[x], rk[y]); pa[y] = x; eg[x] += eg[y]; if (rk[x] == rk[y]) rk[x]++; } 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 (u <= n && v <= n){ if (low[v] <= num[u]){ un(u,v); } else{ eg[fin(u)]++; eg[fin(v)]++; } printf("%d %d\n",u,v); } low[u] = min(low[v], low[u]); } else if (v != p[u]){ low[u] = min(num[v], low[u]); } } } 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)); init(n); dfs(1); int ans = 0; for (int i = 1; i <= n; i++){ if (i == pa[i] && eg[i] == 1) ans++; } printf("%d",ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 31572 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 31572 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 31572 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 71 ms | 37952 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 31572 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |