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;
typedef long long ll;
#define int ll
#define rep(i, n) for(int i = 1; (i) <= (n); ++i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define ford(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define FORD(i, n) for(int i = ((n) - 1); i >= 0; --i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task "FFILL"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
const int N = 1e5 + 3;
const int LIM = (1 << 16) + 3;
const int INF = 1e9 + 1;
const int LOG = 16;
int n, m, q;
vector<int> g[N];
int timedfs = 0;
pii e[N];
int up[N][LOG + 1], tin[N], tout[N], ans[N], b[N], bit[N];
bool c[N];
void update(int u, int v)
{
for(; u <= n; u += u & -u) bit[u] += v;
}
int get(int u)
{
int res = 0;
for(; u; u -= u & -u) res += bit[u];
return res;
}
void dfs(int u, int p)
{
tin[u] = ++timedfs;
up[u][0] = p;
forn(i, 1, LOG) up[u][i] = up[up[u][i - 1]][i - 1];
for(int v : g[u]) if(v != p) dfs(v, u);
tout[u] = timedfs;
}
int root(int u)
{
ford(i, LOG, 0) if(get(tin[u]) == get(tin[up[u][i]]))
u = up[u][i];
return u;
}
void solve()
{
cin >> n >> m >> q;
rep(i, n - 1)
{
int u, v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
e[i] = {u, v};
}
dfs(1, 1);
rep(i, n) update(tin[i], 1), update(tout[i] + 1, -1), ans[i] = 1;
rep(_, m)
{
int idx;
cin >> idx;
int u = e[idx].fi, v = e[idx].se;
if(up[u][0] == v) swap(u, v);
if(c[v])
{
ans[v] = b[v] = ans[root(u)];
update(tin[v], 1);
update(tout[v] + 1, -1);
}
else
{
ans[root(u)] += ans[v] - b[v];
update(tin[v], -1);
update(tout[v] + 1, 1);
}
c[v] ^= 1;
}
rep(_, q)
{
int u;
cin >> u;
cout << ans[root(u)] << endl;
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int TC = 1;
if(fopen("note.inp", "r"))
{
freopen("note.inp", "r", stdin);
freopen("note.out", "w", stdout);
}
while(TC--)
{
solve();
}
return 0;
}
Compilation message (stderr)
synchronization.cpp: In function 'int main()':
synchronization.cpp:129:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
129 | freopen("note.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:130:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
130 | freopen("note.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |