#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
const int inf=1e9, lg=18;
int n, q1, q2, m, time_;
vector<int>C, Dt, Ft, Bit;
vector<vector<int>>A, Lca;
map<int, pair<int, int>>mp;
void pre(){
C.clear(), Dt.clear(), Ft.clear(), Bit.clear(), A.clear(), mp.clear(), Lca.clear();
C.resize(n+1, 1), Dt.resize(n+1), Ft.resize(n+1), Bit.resize(3*n), A.resize(n+1), Lca.resize(n+1, vector<int>(lg+1));
m=n-1, time_=1;
}
void dfs(int u, int p){
Dt[u]=time_++;
Lca[u][0]=p;
for(int j=1;j<=lg;j++){
Lca[u][j]=Lca[Lca[u][j-1]][j-1];
}
for(int i=0;i<A[u].size();i++){
int v=A[u][i];
if(v!=p)
dfs(v, u);
}
Ft[u]=time_++;
}
int g(int i){
return i-(i&(-i));
}
int h(int i){
return i+(i&(-i));
}
void inc(int ind, int delta){
while(ind<=n){
Bit[ind]+=delta;
ind=h(ind);
}
}
int get(int ind){
int sum=0;
while(ind>=1){
sum+=Bit[ind];
ind=g(ind);
}
return sum;
}
int find_root(int u){
int lca=u;
for(int j=lg;j>=0;j--){
if(get(Dt[u])==get(Dt[Lca[lca][j]]))
lca=Lca[lca][j];
}
return lca;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>q1>>q2;
pre();
int cnt=1;
while(m--){
int u, v;
cin>>u>>v;
A[u].push_back(v);
A[v].push_back(u);
mp[cnt++]={u, v};
}
vector<bool>Active(n);
vector<int>Q1(q1);
for(int i=0;i<q1;i++){
cin>>Q1[i];
}
int node;
cin>>node;
dfs(node, node);
for(int i=1;i<=n;i++){
inc(Dt[i], 1);
inc(Ft[i], -1);
}
for(int i=0;i<q1;i++){
int id=Q1[i];
int u=mp[id].FF, v=mp[id].SS;
if(Dt[u]>Dt[v])
swap(u, v);
if(!Active[id]){
int root=find_root(u);
C[root]+=C[v];
C[v]=0;
inc(Dt[v], -1);
inc(Ft[v], 1);
}
else if(Active[id]){
inc(Dt[v], 1);
inc(Ft[v], -1);
}
Active[id]=!Active[id];
}
cout<<C[node];
}
Compilation message
synchronization.cpp: In function 'void dfs(int, int)':
synchronization.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i=0;i<A[u].size();i++){
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
30404 KB |
Output is correct |
2 |
Correct |
112 ms |
30504 KB |
Output is correct |
3 |
Incorrect |
122 ms |
33864 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
256 ms |
33220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |