#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;
int n, q1, q2, m;
vector<vector<int>>A;
map<int, pair<int, int>>mp;
void pre(){
A.clear(), mp.clear();
A.resize(n+1);
m=n-1;
}
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;
if(u>v)
swap(u, v);
A[u].push_back(v);
A[v].push_back(u);
mp[cnt++]={u, v};
}
vector<int>Mnf(n+1), Mxf(n+1);
for(int i=1;i<=n;i++){
Mnf[i]=Mxf[i]=i;
}
set<array<int, 2>>S;
for(int i=1;i<=n;i++){
S.insert({i, i});
}
vector<bool>Active(n);
while(q1--){
int id;
cin>>id;
int u=mp[id].FF, v=mp[id].SS;
int L=u, R=v;
array<int, 2>a={u, inf};
auto it=S.upper_bound(a);
a=*--it;
L=a[0];
a={v, inf};
it=S.upper_bound(a);
a=*--it;
R=a[1];
if(!Active[id]){
Mxf[L]=Mxf[R], Mnf[R]=Mnf[L];
a={u, inf};
it=S.upper_bound(a);
S.erase(--it);
a={v, inf};
it=S.upper_bound(a);
S.erase(--it);
S.insert({L, R});
}
else{
Mnf[u]=Mnf[v]=Mnf[L];
Mxf[u]=Mxf[v]=Mxf[R];
a={L, R};
S.erase(a);
S.insert({L, u});
S.insert({v, R});
}
Active[id]=!Active[id];
}
for(int i=2;i<=n;i++){
Mxf[i]=max(Mxf[i], Mxf[i-1]);
}
for(int i=n-1;i>=1;i--){
Mnf[i]=min(Mnf[i], Mnf[i+1]);
}
while(q2--){
int x;
cin>>x;
cout<<Mxf[x]-Mnf[x]+1<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
140 ms |
18392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
24 ms |
2288 KB |
Output is correct |
8 |
Correct |
386 ms |
20604 KB |
Output is correct |
9 |
Correct |
373 ms |
20608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
329 ms |
18700 KB |
Output is correct |
2 |
Correct |
151 ms |
20224 KB |
Output is correct |
3 |
Correct |
124 ms |
20356 KB |
Output is correct |
4 |
Correct |
124 ms |
20356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |