#include <bits/stdc++.h>
#include <unordered_map>
#define up(i,a,b) for(int i=a;i<=b;i++)
#define down(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a-1;i>=b;i--)
#define self (*this)
#define pb push_back
#define CL(x) (x<<1)
#define CR(x) (x<<1|1)
#define x first
#define y second
#define Kamisama
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int maxn=1e5+7;
const int maxm=1e4+7;
const ll mod=123456789;
const int inf=1e9;
template<typename T> inline void Read(T &x){
register char c;
bool neg=false;
for(c=getchar();c<'0'||c>'9';c=getchar()) if(c=='-') neg=true;
for(x=0;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
if(neg) x=-x;
}
template<typename T> inline void Write(T x){
if(x<0) putchar('-'), x=-x;
if(x>9) Write(x/10);
putchar(x%10+'0');
}
int n,m,q;
int in[maxn],out[maxn],pos[maxn];
int L[4*maxn],R[4*maxn],it[4*maxn];
int res[maxn],last[maxn];
bool avail[maxn];
struct Neko{int x,y;}e[maxn];
vector<int> adj[maxn];
inline void Enter(){
cin>>n>>m>>q;
rep(i,1,n){
cin>>e[i].x>>e[i].y;
adj[e[i].x].pb(e[i].y);
adj[e[i].y].pb(e[i].x);
}
}
inline void Build(const int &x, const int &low, const int &high){
if(low>high) return;
L[x]=low; R[x]=high;
if(low==high){
it[x]=out[pos[low]];
return;
}
int mid=(low+high)>>1;
Build(CL(x),low,mid);
Build(CR(x),mid+1,high);
it[x]=max(it[CL(x)],it[CR(x)]);
}
inline void Update(const int &x, const int &p, const int &v){
if(L[x]>p || R[x]<p) return;
if(L[x]==R[x]){
it[x]=v;
return;
}
Update(CL(x),p,v);
Update(CR(x),p,v);
it[x]=max(it[CL(x)],it[CR(x)]);
}
inline int Get(const int &x, const int &p, const int &v){
if(L[x]>p || it[x]<v) return -1;
if(L[x]==R[x]) return pos[L[x]];
int childRight=Get(CR(x),p,v);
if(childRight!=-1) return childRight;
return Get(CL(x),p,v);
}
inline void Init(){
function<void(int)> Dfs=[&](const int &u){
static int nVisit=0;
in[u]=++nVisit;
pos[nVisit]=u;
for(int v: adj[u]) if(!in[v]) Dfs(v);
out[u]=nVisit;
};
Dfs(1);
Build(1,1,n);
fill(res,res+n+1,1);
}
inline void ChangeState(const int &eid, int u, int v){
if(!avail[eid]){
if(in[u]>in[v]) swap(u,v);
int root=Get(1,in[u],out[u]);
res[root]+=res[v]-last[v];
Update(1,in[v],0);
avail[eid]=true;
} else{
if(in[u]>in[v]) swap(u,v);
int root=Get(1,in[u],out[u]);
res[v]=last[v]=res[root];
Update(1,in[v],out[v]);
avail[eid]=false;
}
}
inline void Solve(){
for(int x;m;m--) cin>>x,ChangeState(x,e[x].x,e[x].y);
for(int x;q;q--) cin>>x,cout<<res[Get(1,in[x],out[x])]<<'\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL),cout.tie(NULL);
#undef Kamisama
#ifdef Kamisama
#define task "TEST"
freopen(task".INP","r",stdin);
freopen(task".OUT","w",stdout);
#endif // Kamisama
//
Enter();
Init();
Solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2808 KB |
Output is correct |
2 |
Correct |
5 ms |
2816 KB |
Output is correct |
3 |
Correct |
4 ms |
2964 KB |
Output is correct |
4 |
Correct |
4 ms |
2964 KB |
Output is correct |
5 |
Correct |
4 ms |
2964 KB |
Output is correct |
6 |
Correct |
5 ms |
2996 KB |
Output is correct |
7 |
Correct |
21 ms |
4164 KB |
Output is correct |
8 |
Correct |
20 ms |
4372 KB |
Output is correct |
9 |
Correct |
21 ms |
4564 KB |
Output is correct |
10 |
Correct |
242 ms |
14872 KB |
Output is correct |
11 |
Correct |
247 ms |
16652 KB |
Output is correct |
12 |
Correct |
222 ms |
22984 KB |
Output is correct |
13 |
Correct |
218 ms |
22984 KB |
Output is correct |
14 |
Correct |
185 ms |
22984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
143 ms |
22984 KB |
Output is correct |
2 |
Correct |
163 ms |
22984 KB |
Output is correct |
3 |
Correct |
104 ms |
25528 KB |
Output is correct |
4 |
Correct |
128 ms |
25544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
25544 KB |
Output is correct |
2 |
Correct |
5 ms |
25544 KB |
Output is correct |
3 |
Correct |
4 ms |
25544 KB |
Output is correct |
4 |
Correct |
5 ms |
25544 KB |
Output is correct |
5 |
Correct |
4 ms |
25544 KB |
Output is correct |
6 |
Correct |
6 ms |
25544 KB |
Output is correct |
7 |
Correct |
23 ms |
25544 KB |
Output is correct |
8 |
Correct |
318 ms |
26208 KB |
Output is correct |
9 |
Correct |
235 ms |
26360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
229 ms |
29064 KB |
Output is correct |
2 |
Correct |
136 ms |
29064 KB |
Output is correct |
3 |
Correct |
138 ms |
29064 KB |
Output is correct |
4 |
Correct |
132 ms |
29172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
29172 KB |
Output is correct |
2 |
Correct |
4 ms |
29172 KB |
Output is correct |
3 |
Correct |
4 ms |
29172 KB |
Output is correct |
4 |
Correct |
5 ms |
29172 KB |
Output is correct |
5 |
Correct |
6 ms |
29172 KB |
Output is correct |
6 |
Correct |
27 ms |
29172 KB |
Output is correct |
7 |
Correct |
337 ms |
29172 KB |
Output is correct |
8 |
Correct |
273 ms |
29172 KB |
Output is correct |
9 |
Correct |
268 ms |
29172 KB |
Output is correct |
10 |
Correct |
217 ms |
29172 KB |
Output is correct |
11 |
Correct |
168 ms |
29172 KB |
Output is correct |
12 |
Correct |
167 ms |
29172 KB |
Output is correct |
13 |
Correct |
143 ms |
29220 KB |
Output is correct |