#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ar array
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, q; cin >> n >> m >> q;
vector <int> X(n - 1), Y(n - 1);
for ( int i = 0; i < n - 1; i++ ){
cin >> X[i] >> Y[i];
--X[i], --Y[i];
}
vector <int> state(n - 1), R(n - 1, -1), L(n - 1, m);
for ( int i = 0; i < m; i++ ){
int x; cin >> x;
--x;
if ( L[x] == m ) L[x] = i;
R[x] = i;
state[x] ^= 1;
}
for ( int i = 0; i < n - 1; i++ ){
if ( state[i] > 0 ) R[i] = m;
}
auto calc = [&](int rt){
vector <vector<ar<int,2>>> adj(n);
for ( int i = 0; i < n - 1; i++ ){
adj[X[i]].pb({Y[i], i});
adj[Y[i]].pb({X[i], i});
}
auto dfs = [&](auto dfs, int u, int p, int r) -> int{
int ret = 1;
for ( auto &[v, j]: adj[u] ){
if ( v != p ){
if ( r >= L[j] ){
ret += dfs(dfs, v, u, min(r, R[j]));
}
}
}
return ret;
};
return dfs(dfs, rt, -1, m);
};
while ( q-- ){
int x; cin >> x;
cout << calc(x - 1) << '\n';
}
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
26 ms |
12496 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8042 ms |
10392 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
452 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |