This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define ld long double
#define vi vector<int>
#define vii vector<vector<int>>
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define per(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
using namespace std;
const int MOD = 1e9 + 7;
int add(int a, int b) {
a += b;
if (a >= MOD) a -= MOD;
return a;
}
int mul(int a, int b) {
(a *= b) %= MOD;
return a;
}
int ceil(int x, int y) {
return (x + y - 1) / y;
}
int bin_pow(int x, int y) {
int res = 1;
while (y) {
if (y & 1) res = res * x % MOD;
x = x * x % MOD;
y >>= 1;
}
return res;
}
template<class T> bool minimize(T& a, T b) {
if (a > b) return a = b, true;
return false;
}
template<class T> bool maximize(T& a, T b) {
if (a < b) return a = b, true;
return false;
}
const int INF = 1e17;
const int maxn = 2e5 + 5;
int n, m, k;
int status[maxn + 5], c[maxn + 5];
set<int> s[maxn + 5], lmouse[maxn + 5];
vector<int> g[maxn + 5];
pair<int, int> moony[maxn + 5];
void solve(int tc) {
cin >> n >> m >> k;
vector<int> data(m + 1);
for (int i = 1; i < n; ++i) {
int u, v; cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
moony[i] = make_pair(u, v);
}
for (int i = 1; i <= n; ++i) {
s[i].insert(i);
lmouse[i].insert(i);
}
for (int i = 1; i <= m; ++i) cin >> data[i];
for (int i = 1; i <= k; ++i) cin >> c[i];
for (int i = 1; i <= m; ++i) {
int id = data[i];
auto [u, v] = moony[id];
status[id] ^= 1;
if (status[id]) {
for (int k : lmouse[u])
for (int x : s[v]) s[k].insert(x);
for (int k : lmouse[v])
for (int x : s[u]) s[k].insert(x);
lmouse[u].insert(v);
lmouse[v].insert(u);
} else {
lmouse[u].erase(v);
lmouse[v].erase(u);
}
}
for (int i = 1; i <= k; ++i)
cout << (int)s[c[i]].size() << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int tc = 1;
//cin >> tc;
for (int i = 1; i <= tc; ++i) {
solve(i);
}
}
# | 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... |