#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(){
Read(n); Read(m); Read(q);
rep(i,1,n){
Read(e[i].x); Read(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--) Read(x),ChangeState(x,e[x].x,e[x].y);
for(int x;q;q--) Read(x),Write(res[Get(1,in[x],out[x])]),putchar('\n');
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL),cout.tie(NULL);
#undef Kamisama
#ifdef Kamisama
#define task "SYNCHRONIZATION"
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 |
4 ms |
2808 KB |
Output is correct |
2 |
Correct |
5 ms |
2812 KB |
Output is correct |
3 |
Correct |
4 ms |
2888 KB |
Output is correct |
4 |
Correct |
4 ms |
3020 KB |
Output is correct |
5 |
Correct |
4 ms |
3020 KB |
Output is correct |
6 |
Correct |
6 ms |
3020 KB |
Output is correct |
7 |
Correct |
22 ms |
3820 KB |
Output is correct |
8 |
Correct |
21 ms |
3820 KB |
Output is correct |
9 |
Correct |
18 ms |
3872 KB |
Output is correct |
10 |
Correct |
298 ms |
11984 KB |
Output is correct |
11 |
Correct |
240 ms |
12064 KB |
Output is correct |
12 |
Correct |
229 ms |
18328 KB |
Output is correct |
13 |
Correct |
212 ms |
18328 KB |
Output is correct |
14 |
Correct |
151 ms |
18328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
18328 KB |
Output is correct |
2 |
Correct |
110 ms |
18328 KB |
Output is correct |
3 |
Correct |
87 ms |
18328 KB |
Output is correct |
4 |
Correct |
92 ms |
18328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
18328 KB |
Output is correct |
2 |
Correct |
4 ms |
18328 KB |
Output is correct |
3 |
Correct |
4 ms |
18328 KB |
Output is correct |
4 |
Correct |
4 ms |
18328 KB |
Output is correct |
5 |
Correct |
4 ms |
18328 KB |
Output is correct |
6 |
Correct |
5 ms |
18328 KB |
Output is correct |
7 |
Correct |
19 ms |
18328 KB |
Output is correct |
8 |
Correct |
231 ms |
18424 KB |
Output is correct |
9 |
Correct |
234 ms |
18544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
231 ms |
18544 KB |
Output is correct |
2 |
Correct |
117 ms |
18544 KB |
Output is correct |
3 |
Correct |
106 ms |
18576 KB |
Output is correct |
4 |
Correct |
112 ms |
18704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
18704 KB |
Output is correct |
2 |
Correct |
4 ms |
18704 KB |
Output is correct |
3 |
Correct |
5 ms |
18704 KB |
Output is correct |
4 |
Correct |
4 ms |
18704 KB |
Output is correct |
5 |
Correct |
5 ms |
18704 KB |
Output is correct |
6 |
Correct |
31 ms |
18704 KB |
Output is correct |
7 |
Correct |
262 ms |
18704 KB |
Output is correct |
8 |
Correct |
222 ms |
18704 KB |
Output is correct |
9 |
Correct |
210 ms |
18704 KB |
Output is correct |
10 |
Correct |
176 ms |
18704 KB |
Output is correct |
11 |
Correct |
146 ms |
18704 KB |
Output is correct |
12 |
Correct |
139 ms |
18704 KB |
Output is correct |
13 |
Correct |
121 ms |
18704 KB |
Output is correct |