#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
int N, M, Q;
int timer = 1;
int anc[100005][20];
int tin[100005], tout[100005];
vector<int> g[100005];
int bit[100005], info[100005], last_sync[100005];
bool active[100005];
pair<int,int> edges[2*100005];
void dfs(int node = 1, int p = 0) {
anc[node][0] = p;
for (int i = 1; i < 20 && anc[node][i-1]; i++) {
anc[node][i] = anc[anc[node][i-1]][i-1];
}
info[node] = 1;
tin[node] = timer++;
for (int u : g[node]){
if (u != p)
dfs(u, node);
}
tout[node] = timer;
}
void add(int i, int v) {
for (; i <= N; i += (i & (-i))) bit[i] += v;
}
int get(int i) {
int r = 0;
for (; i; i -= (i & (-i))) r += bit[i];
return r;
}
int find_anc(int node) {
int lca = node;
for (int i = 19; ~i; i--) {
if (anc[lca][i] && get(tin[anc[lca][i]]) == get(tin[node]))
lca = anc[lca][i];
}
return lca;
}
void solve(){
cin >> N >> M >> Q;
for (int i = 0; i < N; i++) {
int v, u; cin >> v >> u;
edges[i].first = v;
edges[i].second = u;
g[v].push_back(u);
g[u].push_back(v);
}
dfs();
for (int i = 1; i < N+1; i++) {
add(tin[i], -1);
add(tout[i], 1);
}
for (int i = 0; i < M; i++) {
int line; cin >> line;
int u = edges[line].first, v = edges[line].second;
if (anc[u][0] == v) swap(u,v);
if (active[line]) {
info[v] = last_sync[v] = info[find_anc(u)];
add(tin[v], -1);
add(tout[v], 1);
} else {
info[find_anc(u)] += info[v] - last_sync[v];
add(tin[v], 1);
add(tout[v], -1);
}
active[line] = !active[line];
}
for (int i = 0; i < Q; i++) {
int node; cin >> node;
cout << info[find_anc(node)] << '\n';
}
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int t = 1;
while(t--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Runtime error |
601 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
109 ms |
20424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2837 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |