//#pragma optimization_level 3
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset;
*/
#define fr first
#define sc second
#define vec vector
#define pb push_back
#define pii pair<int, int>
#define forr(x,y,z) for(int x = (int)y ; x <= (int)z ; ++x)
#define forn(x,y) for(int x = 1; x <= (int)y; ++x)
#define all(x) (x).begin(),(x).end()
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef unsigned int uint;
typedef complex<ll> point;
const int nmax = 100005;
const ll linf = 1e18;
const ll mod = 1e9+7;
const int inf = 1e9;
int n, m , q;
vec < int > g[nmax];
int tin[nmax], tout[nmax], tt;
int bit[nmax];
pii ed[nmax];
int up[nmax][17];
int old[nmax], cur[nmax], active[nmax];
void update(int pos , int val){
for(;pos <= n; pos += pos&-pos){
bit[pos] += val;
}
}
int query(int pos ){
int rs = 0;
for(;pos > 0 ; pos -= pos&-pos){
rs += bit[pos];
}
return rs;
}
void dfs(int nod , int p){
tin[nod] = ++tt;
up[nod][0] = p;
forn(i,16){
up[nod][i] = up[up[nod][i-1]][i-1];
}
for(int j : g[nod]){
if(j != p){
dfs(j,nod);
}
}
tout[nod] = tt;
update(tin[nod],1);
update(tout[nod]+1,-1);
}
int find_root(int nod){
int p = nod;
int qr = query(tin[nod]);
for(int i = 16 ; i >= 0 ; i--){
if(query(tin[up[p][i]]) == qr){
p = up[p][i];
}
}
return p;
}
int a, b;
int main(){
fast
cin >> n >> m >> q;
forn(i,n-1){
cin >> a >> b;
g[a].pb(b);
g[b].pb(a);
ed[i] = {a,b};
active[i] = 0;
}
forn(i,n-1){
if(up[ed[i].fr][0]!=ed[i].sc){
swap(ed[i].fr,ed[i].sc);
}
}
forn(i,n){
old[i] = 0;
cur[i] = 1;
}
dfs(1,1);
int ei;
forn(jj,m){
cin >> ei;
if(active[ei]){
int rt = find_root(ed[ei].sc);
cur[ed[ei].fr] = cur[rt];
old[ed[ei].fr] = cur[rt];
update(tin[ed[ei].fr],1);
update(tout[ed[ei].fr]+1,-1);
}else{
int rt = find_root(ed[ei].sc);
cur[rt] += cur[ed[ei].fr] - old[ed[ei].fr];
update(tin[ed[ei].fr],-1);
update(tout[ed[ei].fr]+1,1);
}
active[ei] ^= 1;
}
forn(i,q){
cin >> a;
cout << cur[find_root(a)] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Incorrect |
6 ms |
2688 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
18168 KB |
Output is correct |
2 |
Correct |
114 ms |
18040 KB |
Output is correct |
3 |
Correct |
111 ms |
20216 KB |
Output is correct |
4 |
Correct |
119 ms |
20344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
6 |
Correct |
7 ms |
2944 KB |
Output is correct |
7 |
Correct |
24 ms |
4480 KB |
Output is correct |
8 |
Correct |
307 ms |
20472 KB |
Output is correct |
9 |
Correct |
317 ms |
20512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
303 ms |
20600 KB |
Output is correct |
2 |
Correct |
173 ms |
20728 KB |
Output is correct |
3 |
Correct |
167 ms |
20856 KB |
Output is correct |
4 |
Correct |
178 ms |
20988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2688 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Incorrect |
6 ms |
2688 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |