이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left224
#define right right224
#define next next224
#define rank rank224
#define prev prev224
#define y1 y1224
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define mp make_pair
const string FILENAME = "input";
const int MAXN = 100228;
int n, m, q;
vector<pair<int, int> > g[MAXN];
int pr[MAXN];
int timer = 0;
int downe[MAXN];
int who[MAXN];
int dp[MAXN];
int ob[MAXN];
bool used[MAXN];
int in[MAXN], out[MAXN];
void dfs(int u, int p) {
pr[u] = p;
timer++;
in[u] = timer;
who[timer] = u;
for (auto h: g[u]) {
if (h.first == p) {
continue;
}
downe[h.second] = h.first;
dfs(h.first, u);
}
out[u] = timer;
}
int d[MAXN * 4];
void update(int v, int l, int r, int pos, int x) {
if (l == r) {
d[v] = x;
return;
}
int mid = (l + r) >> 1;
if (pos <= mid) {
update(v * 2, l, mid, pos, x);
} else {
update(v * 2 + 1, mid + 1, r, pos, x);
}
d[v] = max(d[v * 2], d[v * 2 + 1]);
}
int get(int v, int l, int r, int tl, int tr, int x) {
if (l > r || tl > r || l > tr || tl > tr || d[v] < x) {
return -1;
}
if (l == r) {
return who[l];
}
int mid = (l + r) >> 1;
int pos = -1;
if (d[v * 2 + 1] >= x) {
pos = get(v * 2 + 1, mid + 1, r, tl, tr, x);
}
if (pos == -1 && d[v * 2] >= x) {
pos = get(v * 2, l, mid, tl, tr, x);
}
return pos;
}
int getRoot(int v) {
int cur = get(1, 1, n, 1, in[v], out[v]);
if (cur != -1) {
return cur;
}
return 1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//read(FILENAME);
cin >> n >> m >> q;
for (int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
g[a].emplace_back(b, i);
g[b].emplace_back(a, i);
}
dfs(1, 0);
for (int i = 1; i <= n; i++) {
dp[i] = 1;
}
for (int i = 2; i <= n; i++) {
update(1, 1, n, in[i], out[i]);
}
for (int i = 1; i <= m; i++) {
int id;
cin >> id;
int y = downe[id];
int x = pr[y];
if (!used[id]){
int root = getRoot(x);
dp[root] += dp[y] - ob[y];
update(1, 1, n, in[y], 0);
} else {
int root = getRoot(x);
dp[y] = dp[root];
ob[y] = dp[root];
update(1, 1, n, in[y], out[y]);
}
used[id] ^= 1;
}
for (int i = 1; i <= q; i++) {
int x;
cin >> x;
cout << dp[getRoot(x)] << '\n';
}
return 0;
}
# | 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... |