#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';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
15 ms |
348 KB |
Output is correct |
6 |
Correct |
4133 ms |
2780 KB |
Output is correct |
7 |
Execution timed out |
8013 ms |
3424 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8058 ms |
22112 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
123 ms |
768 KB |
Output is correct |
6 |
Correct |
318 ms |
856 KB |
Output is correct |
7 |
Execution timed out |
8032 ms |
3296 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8013 ms |
20128 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
38 ms |
632 KB |
Output is correct |
5 |
Correct |
7206 ms |
3928 KB |
Output is correct |
6 |
Execution timed out |
8045 ms |
3684 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |