#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int N = 100'010;
int n, m, q;
vector<pair<int,int>> e;
vector<pair<int,int>> vals;
vector<int> g[N];
bool state[N];
int dfs(int at, int mx = inf, int p = -1) {
// cout << at << " " << mx << endl;
int ans=1;
for(int ed:g[at]) {
int to = (e[ed].first^e[ed].second^at);
if(to == p)continue;
if(vals[ed].first <= mx) {
ans+=dfs(to, min(mx, vals[ed].second), at);
}
}
return ans;
}
int main () {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> q;
for(int i = 1;i<n;i++) {
int u, v;
cin >> u >> v;
e.push_back({u, v});
vals.push_back({inf,-inf});
}
for(int i = 0;i<m;i++) {
int c;
cin >> c;
c--;
state[c]^=1;
if(state[c] == 1 and vals[c].first == inf) {
vals[c].first = i;
}
else vals[c].second = i;
}
for(int i = 0;i<n-1;i++) {
if(vals[i].first == inf)continue;
if(vals[i].second == -inf)vals[i].second = inf;
g[e[i].first].push_back(i);
g[e[i].second].push_back(i);
}
while(q--) {
int a;
cin >> a;
// dfs(a);
cout << dfs(a) << "\n";
// cout << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
13504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
10440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |