# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
220613 |
2020-04-08T08:57:52 Z |
atoiz |
Mergers (JOI19_mergers) |
C++14 |
|
98 ms |
33332 KB |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 500007;
int N, K, open = 0, ans = -1;
int dsu[MAXN], group[MAXN], last[MAXN], val[MAXN];
vector<int> adj[MAXN], add[MAXN];
int root(int u) { return (dsu[u] != u ? dsu[u] = root(dsu[u]) : u); }
void dfs(int u, int p)
{
dsu[u] = u;
for (int v : add[u]) {
if (dsu[v]) val[root(v)] -= 2;
}
for (int v : adj[u]) if (v != p) {
dfs(v, u);
dsu[v] = u;
val[u] += val[v];
}
if (!val[u]) ++val[u], ++ans;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> K;
for (int i = 0; i < N - 1; ++i) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int u = 1; u <= N; ++u) {
cin >> group[u];
if (last[group[u]]) {
int v = last[group[u]];
add[u].push_back(v);
add[v].push_back(u);
++val[u], ++val[v];
}
last[group[u]] = u;
}
dfs(1, 0);
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
23808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
23808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
23808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
33332 KB |
Output is correct |
2 |
Incorrect |
68 ms |
30704 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
23808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |