This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) cerr << #x << ": " << x << endl;
#define ii pair<int,int>
#define fi first
#define se second
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
int n,m,q,d[N],first[N],ans = 0;
vector<ii>p[N],c[N];
bool on[N];
int getpos(int k,int last)
{
int l = 0,r = c[k].size()-1;
int pos = -1;
while(l <= r)
{
int mid = l + r >> 1;
if(c[k][mid].fi < last)
{
pos = mid;
l = mid + 1;
}
else
r = mid - 1;
}
return pos;
}
void dfs(int x,int u,int last)
{
ans++;
for(auto v : p[u])
{
if(v.fi == x)
continue;
int pos = getpos(v.se, last);
if(pos == -1)
continue;
dfs(u,v.fi ,min(last, c[v.se][pos].se));
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>m>>q;
for(int i = 1;i < n;i++)
{
int u,v;
cin>>u>>v;
p[u].push_back(ii(v,i));
p[v].push_back(ii(u,i));
}
for(int i = 1;i <= m;i++)
{
int x;
cin>>x;
if(!on[x])
first[x] = i;
else
c[x].push_back(ii(first[x], i));
on[x] ^= 1;
}
for(int i = 1;i < n;i++)
{
if(on[i])
c[i].push_back(ii(first[i], m+1));
}
while(q--)
{
int root;
cin>>root;
dfs(0,root,m+1);
cout<<ans;
}
return 0;
}
Compilation message (stderr)
synchronization.cpp: In function 'int getpos(int, int)':
synchronization.cpp:19:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
19 | int mid = l + r >> 1;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |