# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
128838 | 2019-07-11T10:08:03 Z | sealnot123 | Mergers (JOI19_mergers) | C++14 | 101 ms | 31664 KB |
#include<bits/stdc++.h> #define x first #define y second #define pb push_back #define eb emplace_back #define all(a) (a).begin(),(a).end() #define SZ(a) (int)(a).size() using namespace std; typedef long long LL; typedef pair<LL,LL> PLL; typedef pair<int,int> PII; typedef double D; typedef long double LD; const int N = 500005; vector<int> tree[N], g[N]; int bridge; int state[N], idx[N], lowlink[N]; int n, st, t; void dfs(int u, int p){ idx[u] = lowlink[u] = ++t; int ch = 0; for(int e : g[u]){ if(e == p && !ch){ ch = 1; continue; } if(idx[e]) lowlink[u] = min(lowlink[u], idx[e]); else{ dfs(e, u); lowlink[u] = min(lowlink[u], lowlink[e]); if(lowlink[e] > idx[u]) bridge++; } } } int main(){ int i,j,k,l,a,b,c,d; scanf("%d%d",&n,&st); for(i=1;i<n;i++){ scanf("%d%d",&a,&b); if(a<b) swap(a,b); tree[a].pb(b); } for(i=1;i<=n;i++) scanf("%d",&state[i]); for(i=1;i<=n;i++){ for(int e : tree[i]){ if(state[e] != state[i]){ g[state[e]].pb(state[i]); g[state[i]].pb(state[e]); } } } dfs(1,1); printf("%d",(bridge+1)/2); return 0; } /* 5 4 1 2 2 3 3 4 3 5 1 2 1 3 4 5 4 1 2 2 3 3 4 4 5 1 2 3 4 1 2 2 1 2 1 2 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23800 KB | Output is correct |
2 | Correct | 23 ms | 23800 KB | Output is correct |
3 | Correct | 23 ms | 23800 KB | Output is correct |
4 | Correct | 23 ms | 23800 KB | Output is correct |
5 | Correct | 24 ms | 23800 KB | Output is correct |
6 | Correct | 23 ms | 23800 KB | Output is correct |
7 | Correct | 23 ms | 23804 KB | Output is correct |
8 | Correct | 24 ms | 23804 KB | Output is correct |
9 | Incorrect | 24 ms | 23800 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23800 KB | Output is correct |
2 | Correct | 23 ms | 23800 KB | Output is correct |
3 | Correct | 23 ms | 23800 KB | Output is correct |
4 | Correct | 23 ms | 23800 KB | Output is correct |
5 | Correct | 24 ms | 23800 KB | Output is correct |
6 | Correct | 23 ms | 23800 KB | Output is correct |
7 | Correct | 23 ms | 23804 KB | Output is correct |
8 | Correct | 24 ms | 23804 KB | Output is correct |
9 | Incorrect | 24 ms | 23800 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23800 KB | Output is correct |
2 | Correct | 23 ms | 23800 KB | Output is correct |
3 | Correct | 23 ms | 23800 KB | Output is correct |
4 | Correct | 23 ms | 23800 KB | Output is correct |
5 | Correct | 24 ms | 23800 KB | Output is correct |
6 | Correct | 23 ms | 23800 KB | Output is correct |
7 | Correct | 23 ms | 23804 KB | Output is correct |
8 | Correct | 24 ms | 23804 KB | Output is correct |
9 | Incorrect | 24 ms | 23800 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 70 ms | 27272 KB | Output is correct |
2 | Correct | 101 ms | 31664 KB | Output is correct |
3 | Incorrect | 26 ms | 23968 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 23800 KB | Output is correct |
2 | Correct | 23 ms | 23800 KB | Output is correct |
3 | Correct | 23 ms | 23800 KB | Output is correct |
4 | Correct | 23 ms | 23800 KB | Output is correct |
5 | Correct | 24 ms | 23800 KB | Output is correct |
6 | Correct | 23 ms | 23800 KB | Output is correct |
7 | Correct | 23 ms | 23804 KB | Output is correct |
8 | Correct | 24 ms | 23804 KB | Output is correct |
9 | Incorrect | 24 ms | 23800 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |