# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
104747 | 2019-04-09T04:11:31 Z | Hideo | Mergers (JOI19_mergers) | C++14 | 3000 ms | 384 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mk make_pair #define fr first #define sc second #define vi vector < int > #define vl vector < ll > #define pi pair < int, int > #define pii pair < int, pi > #define vii vector < pi > const int N = 107; const int INF = 1e9 + 7; int us[N], a[N], b[N], m[N], cur[N]; int go[N][N], vis[N]; int n, k, gr = 1, ans; vi g[N], t[N]; void dfs (int v = 1, int p = 0){ for (int to : g[v]){ if (to != p){ dfs(to, v); cur[v] += cur[to]; } } us[a[v]]++; if (us[a[v]] == 1) cur[v]--; if (us[a[v]] == m[a[v]]){ cur[v]++; us[a[v]] = 0; } b[v] = gr; if (cur[v] == 0) gr++; } void dfs2 (int v = 1, int p = 0){ for (int to : g[v]){ if (to != p){ dfs2(to, v); if (b[to] != b[v]){ go[b[v]][b[to]] = 1; go[b[to]][b[v]] = 1; } } } } void findAns (int v = 1, int p = 0){ int c = 0; if (vis[v] == 1){ while(true); } vis[v] = 1; for (int i = 0; i < N; i++){ if (go[v][i] == 1){ if (i != p) findAns(i, v); c++; } } if (c == 1) ans++; } main(){ cin >> n >> k; for (int i = 1; i < n; i++){ int a, b; scanf("%d%d", &a, &b); g[a].pb(b); g[b].pb(a); } for (int i = 1; i <= n; i++){ scanf("%d", &a[i]); m[a[i]]++; } dfs(); dfs2(); findAns(); printf("%d", (ans + 1) / 2); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Execution timed out | 3011 ms | 384 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Execution timed out | 3011 ms | 384 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Execution timed out | 3011 ms | 384 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 3 ms | 384 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 | 2 ms | 256 KB | Output is correct |
2 | Execution timed out | 3011 ms | 384 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |