# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
104754 | 2019-04-09T06:29:21 Z | antimirage | Mergers (JOI19_mergers) | C++14 | 3000 ms | 29764 KB |
#include <bits/stdc++.h> #define fr first #define sc second #define mk make_pair #define pb push_back #define all(s) s.begin(), s.end() using namespace std; const int N = 5e5 + 5; int n, k, x, y, s[N], d[N][55], cnt[N], ans, tin[N], tout[N], timer, level[N], asd[N], sum; vector < vector <int> > g; vector <int> vec; void dfs (int v, int p = 0){ level[v] = level[p] + 1; tin[v] = ++timer; d[v][ s[v] ]++; for (auto to : g[v]){ if (to == p) continue; dfs(to, v); for (int j = 1; j <= k; j++) d[v][j] += d[to][j]; asd[v] += asd[to]; } bool fl = 1; for (int j = 1; j <= k; j++){ if (d[v][j] > 0 && d[v][j] < cnt[j]) fl = 0; } if (fl && v != 1) asd[v]++; else asd[v] = 0; if(v != 1 && fl){ ans = max(ans, asd[v] - 1); if (asd[v] == 1) sum ++; } tout[v] = ++timer; } inline bool upper (int a, int b) { return tin[a] <= tin[b] && tout[b] <= tout[a]; } main(){ cin >> n >> k; g.resize(n + 1); for (int i = 1; i < n; i++){ scanf("%d%d", &x, &y); g[x].pb(y); g[y].pb(x); } for (int i = 1; i <= n; i++){ scanf("%d", &s[i]); cnt[ s[i] ]++; } dfs(1); cout << max( (sum + 1) / 2, ans) << endl; } /** 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 **/
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Incorrect | 2 ms | 384 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Incorrect | 2 ms | 384 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Incorrect | 2 ms | 384 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 148 ms | 29764 KB | Output is correct |
2 | Execution timed out | 3066 ms | 29496 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Incorrect | 2 ms | 384 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |