#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define vll vector<ll>
#define pll pair<ll, ll>
typedef long long ll;
const ll mxN=1e5+5;
const ll inf=1e18;
vector<pll> adj[mxN];
vector<pll> tim[mxN];
vll tep[mxN];
ll n, m, q;
ll dfs(ll cur, ll edge, ll par, ll mx){
if(par!=-1 && (tim[edge].empty() || tim[edge][0].F>=mx)){
return 0;
}
pll it={inf, inf};
if(par!=-1)
it=*prev(upper_bound(tim[edge].begin(), tim[edge].end(), make_pair(mx, 0LL)));
mx=min(mx, it.S);
ll re=1;
for(auto &[x, y]:adj[cur]){
if(x==par) continue;
re+=dfs(x, y, cur, mx);
}
return re;
}
void solve(){
cin>>n>>m>>q;
for(ll i=1;i<=n-1;i++){
ll a, b;
cin>>a>>b;
adj[a].pb({b, i});
adj[b].pb({a, i});
}
for(ll i=0;i<m;i++){
ll a;
cin>>a;
tep[a].pb(i);
}
for(ll i=1;i<=n-1;i++){
if(tep[i].size()%2==1){
tep[i].pb(m);
}
}
for(ll i=1;i<=n-1;i++){
for(ll j=0;j<tep[i].size();j+=2){
tim[i].pb({tep[i][j], tep[i][j+1]});
}
}
for(ll rep=0;rep<q;rep++){
ll tar;
cin>>tar;
cout<<dfs(tar, 0, -1, inf)<<'\n';
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
Compilation message
synchronization.cpp: In function 'void solve()':
synchronization.cpp:54:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(ll j=0;j<tep[i].size();j+=2){
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
7256 KB |
Output is correct |
2 |
Correct |
2 ms |
7260 KB |
Output is correct |
3 |
Correct |
2 ms |
7260 KB |
Output is correct |
4 |
Correct |
2 ms |
7260 KB |
Output is correct |
5 |
Correct |
2 ms |
7516 KB |
Output is correct |
6 |
Correct |
2 ms |
7516 KB |
Output is correct |
7 |
Correct |
7 ms |
8796 KB |
Output is correct |
8 |
Correct |
7 ms |
8792 KB |
Output is correct |
9 |
Correct |
7 ms |
8792 KB |
Output is correct |
10 |
Correct |
60 ms |
21516 KB |
Output is correct |
11 |
Correct |
69 ms |
21684 KB |
Output is correct |
12 |
Correct |
50 ms |
21076 KB |
Output is correct |
13 |
Correct |
50 ms |
20632 KB |
Output is correct |
14 |
Correct |
56 ms |
20608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
25028 KB |
Output is correct |
2 |
Correct |
50 ms |
23504 KB |
Output is correct |
3 |
Correct |
42 ms |
25680 KB |
Output is correct |
4 |
Correct |
45 ms |
24964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
7268 KB |
Output is correct |
2 |
Correct |
2 ms |
7260 KB |
Output is correct |
3 |
Correct |
2 ms |
7520 KB |
Output is correct |
4 |
Correct |
2 ms |
7260 KB |
Output is correct |
5 |
Correct |
2 ms |
7260 KB |
Output is correct |
6 |
Correct |
3 ms |
7512 KB |
Output is correct |
7 |
Correct |
8 ms |
8792 KB |
Output is correct |
8 |
Correct |
74 ms |
21840 KB |
Output is correct |
9 |
Correct |
74 ms |
21940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
21992 KB |
Output is correct |
2 |
Execution timed out |
8090 ms |
26748 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
7260 KB |
Output is correct |
2 |
Correct |
2 ms |
7504 KB |
Output is correct |
3 |
Correct |
2 ms |
7260 KB |
Output is correct |
4 |
Correct |
2 ms |
7512 KB |
Output is correct |
5 |
Correct |
3 ms |
7516 KB |
Output is correct |
6 |
Correct |
59 ms |
8940 KB |
Output is correct |
7 |
Correct |
2049 ms |
22548 KB |
Output is correct |
8 |
Correct |
75 ms |
21908 KB |
Output is correct |
9 |
Execution timed out |
8037 ms |
21164 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |