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>
using namespace std;
#define pb push_back
#define ar array
struct Dsu{
vector <int> fa;
Dsu(int n){
fa.resize(n);
iota(fa.begin(), fa.end(), 0);
}
int get(int u){ return u ^ fa[u] ? fa[u] = get(fa[u]) : u; }
bool merge(int u, int v){
u = get(u), v = get(v);
if ( u == v ) return false;
fa[v] = u;
return true;
}
};
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, q; cin >> n >> m >> q;
vector <int> X(n - 1), Y(n - 1);
for ( int i = 0; i < n - 1; i++ ){
cin >> X[i] >> Y[i];
--X[i], --Y[i];
}
vector <int> e(m);
for ( auto &u: e ){
cin >> u; --u;
}
vector <set<int>> st(n);
for ( int i = 0; i < n; i++ ) st[i].insert(i);
vector <int> state(n - 1);
for ( auto &j: e ){
state[j] ^= 1;
Dsu ds(n);
for ( int i = 0; i + 1 < n; i++ ){
if ( state[i] > 0 ) ds.merge(X[i], Y[i]);
}
vector <vector<int>> c(n);
for ( int i = 0; i < n; i++ ){
int fa = ds.get(i);
for ( auto &j: st[i] ) c[fa].pb(j);
}
for ( int u = 0; u < n; u++ ){
for ( auto &v: c[ds.get(u)] ){
st[u].insert(v);
}
}
}
while ( q-- ){
int x; cin >> x;
cout << st[x - 1].size() << '\n';
}
cout << '\n';
}
# | 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... |