#include <bits/stdc++.h>
using namespace std;
int n,m,qq;
int ans;
vector<pair<int,int> > v[100005];
int f[100005];
int last[100005];
int c[100005];
int x,y;
void dfs(int x,int y,int xx,int yy) {
if (xx<=yy) ++ans;
for (int i=0;i<v[x].size();++i) {
int to=v[x][i].first;
if (to==y) continue;
int xx2;
int yy2=min(yy,last[v[x][i].second]);
xx2=f[v[x][i].second];
if (xx2<=yy2)
dfs(to,x,xx2,yy2);
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>m>>qq;
for (int i=1;i<n;++i) {
cin>>x>>y;
v[x].push_back(make_pair(y,i));
v[y].push_back(make_pair(x,i));
f[i]=m+2;
last[i]=m+1;
}
for (int i=1;i<=m;++i) {
cin>>x;
c[x]^=1;
if (c[x]) {
f[x]=min(f[x],i);
} else last[x]=i;
}
for (int i=1;i<n;++i) {
if (c[i]) last[i]=m+1;
}
for (int i=1;i<=qq;++i) {
cin>>x;
ans=0;
dfs(x,-1,0,1e9);
cout<<ans<<'\n';
}
}
Compilation message
synchronization.cpp: In function 'void dfs(int, int, int, int)':
synchronization.cpp:16:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i=0;i<v[x].size();++i) {
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2684 KB |
Output is correct |
2 |
Correct |
4 ms |
2792 KB |
Output is correct |
3 |
Correct |
6 ms |
2792 KB |
Output is correct |
4 |
Correct |
5 ms |
2924 KB |
Output is correct |
5 |
Correct |
5 ms |
2924 KB |
Output is correct |
6 |
Correct |
5 ms |
2980 KB |
Output is correct |
7 |
Correct |
11 ms |
3548 KB |
Output is correct |
8 |
Incorrect |
11 ms |
3888 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
12508 KB |
Output is correct |
2 |
Correct |
59 ms |
13404 KB |
Output is correct |
3 |
Correct |
58 ms |
17776 KB |
Output is correct |
4 |
Correct |
58 ms |
18924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
18924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
101 ms |
18924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
18924 KB |
Output is correct |
2 |
Correct |
4 ms |
18924 KB |
Output is correct |
3 |
Correct |
5 ms |
18924 KB |
Output is correct |
4 |
Incorrect |
6 ms |
18924 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |