# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
332895 | 2020-12-04T00:23:53 Z | ly20 | Mergers (JOI19_mergers) | C++17 | 51 ms | 37484 KB |
#include <bits/stdc++.h> using namespace std; const int MAXN = 3123; int marc[MAXN], tp[MAXN], sub[MAXN][MAXN]; int n, k; vector <int> grafo[MAXN]; int vl[MAXN]; int resp = 0; void dfs1(int v, int p) { for(int i = 0; i < grafo[v].size(); i++) { int viz = grafo[v][i]; if(viz == p) continue; dfs1(viz, v); for(int j = 1; j <= k; j++) { sub[v][j] += sub[viz][j]; } vl[v] += vl[viz]; } bool ok = true; for(int i = 1; i <= k; i++) { if(sub[v][i] != marc[i] && sub[v][i] != 0) ok = false; } if(ok) vl[v]++; if(p == v && grafo[v].size() == 1) { int viz = grafo[v][0]; ok = true; for(int i = 1; i <= k; i++) { if(sub[viz][i] != marc[i] && sub[viz][i] != 0) ok = false; } if(ok) resp++; } if(p == v) return; if(ok && vl[v] == 1) resp++; } int main() { scanf("%d %d", &n, &k); for(int i = 0; i < n - 1; i++) { int a, b; scanf("%d %d", &a, &b); grafo[a].push_back(b); grafo[b].push_back(a); } for(int i = 1 ; i<= n; i++) { int a; scanf("%d", &a); marc[a]++; tp[i] = a; sub[i][a]++; } dfs1(1, 1); printf("%d\n", (resp + 1) / 2); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 492 KB | Output is correct |
2 | Correct | 1 ms | 876 KB | Output is correct |
3 | Correct | 1 ms | 748 KB | Output is correct |
4 | Correct | 1 ms | 492 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 876 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 876 KB | Output is correct |
9 | Correct | 1 ms | 492 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 876 KB | Output is correct |
12 | Correct | 1 ms | 748 KB | Output is correct |
13 | Correct | 1 ms | 492 KB | Output is correct |
14 | Correct | 48 ms | 748 KB | Output is correct |
15 | Correct | 1 ms | 748 KB | Output is correct |
16 | Correct | 1 ms | 492 KB | Output is correct |
17 | Correct | 1 ms | 492 KB | Output is correct |
18 | Correct | 1 ms | 1004 KB | Output is correct |
19 | Correct | 1 ms | 492 KB | Output is correct |
20 | Correct | 1 ms | 492 KB | Output is correct |
21 | Correct | 1 ms | 876 KB | Output is correct |
22 | Correct | 1 ms | 876 KB | Output is correct |
23 | Correct | 1 ms | 492 KB | Output is correct |
24 | Correct | 1 ms | 492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 492 KB | Output is correct |
2 | Correct | 1 ms | 876 KB | Output is correct |
3 | Correct | 1 ms | 748 KB | Output is correct |
4 | Correct | 1 ms | 492 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 876 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 876 KB | Output is correct |
9 | Correct | 1 ms | 492 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 876 KB | Output is correct |
12 | Correct | 1 ms | 748 KB | Output is correct |
13 | Correct | 1 ms | 492 KB | Output is correct |
14 | Correct | 48 ms | 748 KB | Output is correct |
15 | Correct | 1 ms | 748 KB | Output is correct |
16 | Correct | 1 ms | 492 KB | Output is correct |
17 | Correct | 1 ms | 492 KB | Output is correct |
18 | Correct | 1 ms | 1004 KB | Output is correct |
19 | Correct | 1 ms | 492 KB | Output is correct |
20 | Correct | 1 ms | 492 KB | Output is correct |
21 | Correct | 1 ms | 876 KB | Output is correct |
22 | Correct | 1 ms | 876 KB | Output is correct |
23 | Correct | 1 ms | 492 KB | Output is correct |
24 | Correct | 1 ms | 492 KB | Output is correct |
25 | Correct | 1 ms | 620 KB | Output is correct |
26 | Correct | 29 ms | 28140 KB | Output is correct |
27 | Correct | 10 ms | 13164 KB | Output is correct |
28 | Correct | 45 ms | 26860 KB | Output is correct |
29 | Correct | 51 ms | 26732 KB | Output is correct |
30 | Correct | 11 ms | 13804 KB | Output is correct |
31 | Correct | 1 ms | 620 KB | Output is correct |
32 | Correct | 49 ms | 37484 KB | Output is correct |
33 | Correct | 1 ms | 620 KB | Output is correct |
34 | Correct | 10 ms | 12652 KB | Output is correct |
35 | Correct | 33 ms | 26732 KB | Output is correct |
36 | Incorrect | 9 ms | 12908 KB | Output isn't correct |
37 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 492 KB | Output is correct |
2 | Correct | 1 ms | 876 KB | Output is correct |
3 | Correct | 1 ms | 748 KB | Output is correct |
4 | Correct | 1 ms | 492 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 876 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 876 KB | Output is correct |
9 | Correct | 1 ms | 492 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 876 KB | Output is correct |
12 | Correct | 1 ms | 748 KB | Output is correct |
13 | Correct | 1 ms | 492 KB | Output is correct |
14 | Correct | 48 ms | 748 KB | Output is correct |
15 | Correct | 1 ms | 748 KB | Output is correct |
16 | Correct | 1 ms | 492 KB | Output is correct |
17 | Correct | 1 ms | 492 KB | Output is correct |
18 | Correct | 1 ms | 1004 KB | Output is correct |
19 | Correct | 1 ms | 492 KB | Output is correct |
20 | Correct | 1 ms | 492 KB | Output is correct |
21 | Correct | 1 ms | 876 KB | Output is correct |
22 | Correct | 1 ms | 876 KB | Output is correct |
23 | Correct | 1 ms | 492 KB | Output is correct |
24 | Correct | 1 ms | 492 KB | Output is correct |
25 | Correct | 1 ms | 620 KB | Output is correct |
26 | Runtime error | 45 ms | 10984 KB | Execution killed with signal 6 (could be triggered by violating memory limits) |
27 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 34 ms | 10728 KB | Execution killed with signal 6 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 492 KB | Output is correct |
2 | Correct | 1 ms | 876 KB | Output is correct |
3 | Correct | 1 ms | 748 KB | Output is correct |
4 | Correct | 1 ms | 492 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 876 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 876 KB | Output is correct |
9 | Correct | 1 ms | 492 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 876 KB | Output is correct |
12 | Correct | 1 ms | 748 KB | Output is correct |
13 | Correct | 1 ms | 492 KB | Output is correct |
14 | Correct | 48 ms | 748 KB | Output is correct |
15 | Correct | 1 ms | 748 KB | Output is correct |
16 | Correct | 1 ms | 492 KB | Output is correct |
17 | Correct | 1 ms | 492 KB | Output is correct |
18 | Correct | 1 ms | 1004 KB | Output is correct |
19 | Correct | 1 ms | 492 KB | Output is correct |
20 | Correct | 1 ms | 492 KB | Output is correct |
21 | Correct | 1 ms | 876 KB | Output is correct |
22 | Correct | 1 ms | 876 KB | Output is correct |
23 | Correct | 1 ms | 492 KB | Output is correct |
24 | Correct | 1 ms | 492 KB | Output is correct |
25 | Correct | 1 ms | 620 KB | Output is correct |
26 | Correct | 29 ms | 28140 KB | Output is correct |
27 | Correct | 10 ms | 13164 KB | Output is correct |
28 | Correct | 45 ms | 26860 KB | Output is correct |
29 | Correct | 51 ms | 26732 KB | Output is correct |
30 | Correct | 11 ms | 13804 KB | Output is correct |
31 | Correct | 1 ms | 620 KB | Output is correct |
32 | Correct | 49 ms | 37484 KB | Output is correct |
33 | Correct | 1 ms | 620 KB | Output is correct |
34 | Correct | 10 ms | 12652 KB | Output is correct |
35 | Correct | 33 ms | 26732 KB | Output is correct |
36 | Incorrect | 9 ms | 12908 KB | Output isn't correct |
37 | Halted | 0 ms | 0 KB | - |