이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Author: AkiYuu
TASK:
LANG: C++14
*/
#include <bits/stdc++.h>
#define task "GROUP"
#define ll long long
#define ld long double
#define pb push_back
#define ffw(i,a,b) for (ll i = a; i <= b; i++)
#define fbw(i,b,a) for (ll i = b; i >= a; i--)
#define adj(v,adj,u) for (auto v : adj[u])
#define rep(i,a) for (auto i : a)
#define reset(a) memset(a, 0, sizeof(a))
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
using namespace std;
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// freopen(task".inp", "r", stdin);
// freopen(task".out", "w", stdout);
}
const int mxn = 1e5 + 5;
typedef pair<ll, ll> ii;
vector < int > a[mxn];
int now[mxn], last[mxn];
int up[20][mxn];
int n , m, q;
int tin[mxn], tout[mxn], timer = 0;
bool state[mxn];
int U[mxn], V[mxn];
int BIT[mxn];
void upd(int id, int v ){
for(id; id <= n + 1; id += id & -id){
BIT[id] += v;
}
}
int sum(int id ){
int res = 0;
for ( id; id > 0; id -= id & -id)
res += BIT[id];
return res;
}
void dfs(int u, int p){
tin[u] = ++timer;
up[0][u] = p;
adj(v,a,u){
if ( v == p ) continue;
dfs(v,u);
}
tout[u] = timer;
}
int findlow(int u ){
int ans = u;
fbw(i,18,0) if ( sum(tin[up[i][ans]]) == sum(tin[u]) ) ans = up[i][ans];
return ans;
}
void solve(){
cin >> n >> m >> q;
ffw(i,1,n-1){
int u , v;
cin >> u >> v;
U[i] = u;
V[i] = v;
a[u].pb(v);
a[v].pb(u);
}
dfs(1,1);
ffw(k,1,18) ffw(i,1,n) {
up[k][i] = up[k-1][ up[k-1][i] ];
}
ffw(i,1,n){
now[i] = 1;
last[i] = 0;
state[i] = 0;
upd(tin[i], 1);
upd(tout[i] + 1, -1);
}
while(m--){
int x;
cin >> x;
int u = U[x], v = V[x];
if ( up[0][u] == v ) swap(u,v);
if ( state[x] ) {
now[v] = last[v] = now[ findlow(u) ];
upd(tin[v], 1);
upd(tout[v]+1, -1);
}else {
now[ findlow(u) ] += now[v] - last[v];
upd(tin[v], -1);
upd(tout[v] + 1, 1);
}
state[x] ^= 1;
}
// ffw(i,1,n) cout << now[i] << ' ';
// cout << '\n';
while(q--){
int u; cin >> u;
cout << now[ findlow(u) ] << '\n';
}
}
int main(){
fastio();
int t = 1;
// cin >> t;
while (t--)
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
synchronization.cpp: In function 'void upd(int, int)':
synchronization.cpp:45:9: warning: statement has no effect [-Wunused-value]
45 | for(id; id <= n + 1; id += id & -id){
| ^~
synchronization.cpp: In function 'int sum(int)':
synchronization.cpp:52:11: warning: statement has no effect [-Wunused-value]
52 | for ( id; id > 0; id -= id & -id)
| ^~
# | 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... |