#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "asd"
#define pll pair<ll, ll>
#define pii pair<pll, ll>
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7;
const ll N = 2e5+5;
const int base = 313;
ll n, m, t, k, T, ans, tong, a[N], b[N], c[N], h[N], P[N][20], in[N], out[N], d[N], fe[N];
vector<ll> adj[N];
vector<ll> kq;
bool ok[N];
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n & 1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
void add(ll id, ll x)
{
for(; id <= n; id += id & -id)fe[id] += x;
}
ll get(ll id)
{
ll total = 0;
for(; id; id -= id & -id)total += fe[id];
return total;
}
void dfs(ll u, ll p)
{
for(int i = 1; i < 20; i ++)P[u][i] = P[P[u][i-1]][i-1];
in[u] = ++k;
for(ll v : adj[u])
{
if(v == p)continue;
P[v][0] = u;
dfs(v, u);
}
out[u] = k;
}
ll findp(ll u)
{
ll node = u;
for(int i = 19; i >= 0; i --)
{
if(P[u][i] && get(in[P[u][i]]) == get(in[node]))u = P[u][i];
}
return u;
}
void sol()
{
cin >> n >> m >> t;
for(int i = 1; i < n; i ++)
{
cin >> a[i] >> b[i];
adj[a[i]].pb(b[i]);
adj[b[i]].pb(a[i]);
}
dfs(1, 0);
for(int i = 1; i <= n; i ++)
{
add(in[i], 1);
add(out[i]+1, -1);
d[i] = 1;
}
while(m -- > 0)
{
ll i;
cin >> i;
ll u = a[i], v = b[i];
if(P[u][0] == v)swap(u, v);
if(ok[i])
{
d[v] = d[findp(u)];
}
else
{
d[v] = d[findp(u)] += d[v] - c[v];
c[v] = d[v];
}
//cout << d[findp(a[i])] <<" "<<d[findp(b[i])]<<'\n';
ok[i] = !ok[i];
}
while(t -- > 0)
{
ll u;
cin >> u;
cout << d[findp(u)] << '\n';
}
}
int main()
{
if(fopen(task".INP", "r"))
{
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
/*
5 1
1 2
2 3
3 4
4 5
*/
Compilation message
synchronization.cpp: In function 'int main()':
synchronization.cpp:104:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | freopen(task".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:105:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
105 | freopen(task".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4988 KB |
Output is correct |
2 |
Incorrect |
4 ms |
5028 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
141 ms |
34112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
5068 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
338 ms |
37136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5068 KB |
Output is correct |
2 |
Incorrect |
4 ms |
5028 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |