# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
106079 | 2019-04-16T13:02:06 Z | mzhao | Mergers (JOI19_mergers) | C++11 | 28 ms | 23928 KB |
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #define D(x...) printf(x) #else #define D(x...) #endif #define MN 500100 int N, K, S[MN]; vector<int> adj[MN]; int tot[MN], cnt[MN], ans; int bad[MN]; void dfs(int n, int p) { int cur[8]; for (int i = 1; i <= K; i++) cur[i] = cnt[i]; cnt[S[n]]++; for (int i : adj[n]) if (i != p) { dfs(i, n); bad[n] += bad[i]; } for (int i = 1; i <= K; i++) cur[i] = cnt[i]-cur[i]; while (bad[n] > 1) { bad[n] -= 2; ans++; } if (n == 1) return; bool f = 1; for (int i = 1; i <= K; i++) if (cur[i] && cur[i] != tot[i]) { f = 0; break; } if (f) bad[n] = 1; } int main() { scanf("%d%d", &N, &K); assert(N <= 100); for (int i = 1, A, B; i < N; i++) { scanf("%d%d", &A, &B); adj[A].push_back(B); adj[B].push_back(A); } for (int i = 1; i <= N; i++) { scanf("%d", &S[i]); tot[S[i]]++; } dfs(1, 0); if (bad[1]) ans++; printf("%d\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12160 KB | Output is correct |
2 | Correct | 12 ms | 12160 KB | Output is correct |
3 | Correct | 15 ms | 12160 KB | Output is correct |
4 | Correct | 12 ms | 12032 KB | Output is correct |
5 | Correct | 13 ms | 12160 KB | Output is correct |
6 | Correct | 13 ms | 12160 KB | Output is correct |
7 | Correct | 15 ms | 12160 KB | Output is correct |
8 | Correct | 16 ms | 12160 KB | Output is correct |
9 | Correct | 13 ms | 12160 KB | Output is correct |
10 | Correct | 12 ms | 12160 KB | Output is correct |
11 | Correct | 15 ms | 12032 KB | Output is correct |
12 | Incorrect | 12 ms | 12160 KB | Output isn't correct |
13 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12160 KB | Output is correct |
2 | Correct | 12 ms | 12160 KB | Output is correct |
3 | Correct | 15 ms | 12160 KB | Output is correct |
4 | Correct | 12 ms | 12032 KB | Output is correct |
5 | Correct | 13 ms | 12160 KB | Output is correct |
6 | Correct | 13 ms | 12160 KB | Output is correct |
7 | Correct | 15 ms | 12160 KB | Output is correct |
8 | Correct | 16 ms | 12160 KB | Output is correct |
9 | Correct | 13 ms | 12160 KB | Output is correct |
10 | Correct | 12 ms | 12160 KB | Output is correct |
11 | Correct | 15 ms | 12032 KB | Output is correct |
12 | Incorrect | 12 ms | 12160 KB | Output isn't correct |
13 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12160 KB | Output is correct |
2 | Correct | 12 ms | 12160 KB | Output is correct |
3 | Correct | 15 ms | 12160 KB | Output is correct |
4 | Correct | 12 ms | 12032 KB | Output is correct |
5 | Correct | 13 ms | 12160 KB | Output is correct |
6 | Correct | 13 ms | 12160 KB | Output is correct |
7 | Correct | 15 ms | 12160 KB | Output is correct |
8 | Correct | 16 ms | 12160 KB | Output is correct |
9 | Correct | 13 ms | 12160 KB | Output is correct |
10 | Correct | 12 ms | 12160 KB | Output is correct |
11 | Correct | 15 ms | 12032 KB | Output is correct |
12 | Incorrect | 12 ms | 12160 KB | Output isn't correct |
13 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 28 ms | 23928 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 12160 KB | Output is correct |
2 | Correct | 12 ms | 12160 KB | Output is correct |
3 | Correct | 15 ms | 12160 KB | Output is correct |
4 | Correct | 12 ms | 12032 KB | Output is correct |
5 | Correct | 13 ms | 12160 KB | Output is correct |
6 | Correct | 13 ms | 12160 KB | Output is correct |
7 | Correct | 15 ms | 12160 KB | Output is correct |
8 | Correct | 16 ms | 12160 KB | Output is correct |
9 | Correct | 13 ms | 12160 KB | Output is correct |
10 | Correct | 12 ms | 12160 KB | Output is correct |
11 | Correct | 15 ms | 12032 KB | Output is correct |
12 | Incorrect | 12 ms | 12160 KB | Output isn't correct |
13 | Halted | 0 ms | 0 KB | - |