# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
332886 | 2020-12-03T23:58:58 Z | ly20 | Mergers (JOI19_mergers) | C++17 | 35 ms | 10600 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) 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 | 1 ms | 748 KB | Output is correct |
15 | Correct | 1 ms | 748 KB | Output is correct |
16 | Incorrect | 1 ms | 492 KB | Output isn't correct |
17 | 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 | 1 ms | 748 KB | Output is correct |
15 | Correct | 1 ms | 748 KB | Output is correct |
16 | Incorrect | 1 ms | 492 KB | Output isn't correct |
17 | 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 | 1 ms | 748 KB | Output is correct |
15 | Correct | 1 ms | 748 KB | Output is correct |
16 | Incorrect | 1 ms | 492 KB | Output isn't correct |
17 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 35 ms | 10600 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 | 1 ms | 748 KB | Output is correct |
15 | Correct | 1 ms | 748 KB | Output is correct |
16 | Incorrect | 1 ms | 492 KB | Output isn't correct |
17 | Halted | 0 ms | 0 KB | - |