이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define sz(x) (int)((x).size())
//#define int long long
//#include "robots.h"
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const ll inf = 2e6;
const ll mod = 1e9 + 7;
const int N = 3e6 + 11;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);
//ifstream in(".in");
//ofstream out(".out");
int n, m, q, type[N], L[N], R[N], pos[N], res[N], lst[N], cnt, d[N], from[N], to[N];
vector<int> v[N];
int t[4*N];
void dfs(int nod, int p){
L[nod] = ++cnt;
pos[cnt] = nod;
for(auto it : v[nod]){
if(it == p)continue;
d[it] = d[nod] + 1;
dfs(it, nod);
}
R[nod] = cnt;
}
void build(int v, int l, int r){
if(l == r){
t[v] = R[pos[l]];
return;
}
int mid = (l + r) >> 1;
build(2*v, l, mid);
build(2*v + 1, mid + 1, r);
t[v] = max(t[2*v], t[2*v + 1]);
}
void update(int v, int l, int r, int pos, int val){
if(l == r){
t[v] = val;
return;
}
int mid = (l + r) >> 1;
if(pos <= mid)update(2*v, l, mid, pos, val);else update(2*v + 1, mid + 1, r, pos, val);
t[v] = max(t[2*v], t[2*v + 1]);
}
int find(int v, int l, int r, int pos, int mx){
if(l > pos || t[v] < mx)return 0;
if(l == r)return l;
int mid = (l + r) >> 1;
int x = find(2*v + 1, mid + 1, r, pos, mx);
if(x)return x;
return find(2*v, l, mid, pos, mx);
}
void solve(){
cin >> n >> m >> q;
for(int i = 1; i < n; i++){
cin >> from[i] >> to[i];
v[from[i]].pb(to[i]);
v[to[i]].pb(from[i]);
}
dfs(1, 0);
for(int i = 1; i <= n; i++){
res[i] = 1;
if(d[from[i]] > d[to[i]])swap(from[i], to[i]);
}
build(1, 1, n);
for(int i = 1, e; i <= m; i++){
cin >> e;
if(!type[e]){
res[pos[find(1, 1, n, L[from[e]], R[from[e]])]] += res[to[e]] - lst[e];
update(1, 1, n, L[to[e]], 0);
}else{
res[to[e]] = lst[e] = res[pos[find(1, 1, n, L[from[e]], R[from[e]])]];
update(1, 1, n, L[to[e]], R[to[e]]);
}
type[e] ^= 1;
}
for(int i = 1, x; i <= q; i++){
cin >> x;
cout << res[pos[find(1, 1, n, L[x], R[x])]] << '\n';
}
}
int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
//cout << setprecision(6) << fixed;
int T = 1;
//cin >> T;
while(T--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |