#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, c;
int status[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];
cin >> c;
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);
}
}
cout << (int)s[c].size();
}
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 |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
10 ms |
23728 KB |
Output is correct |
3 |
Incorrect |
11 ms |
23900 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
410 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
23896 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
198 ms |
71632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
23900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |