# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40354 | krauch | Synchronization (JOI13_synchronization) | C++14 | 8055 ms | 55432 KiB |
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;
typedef pair < int, int > PII;
#define F first
#define S second
#define mkp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)
const ll ool = 1e18 + 9;
const int N = 3e5 + 3, oo = 1e9 + 9;
int n, m, Q;
bool open[N];
vector < PII > g[N], vec[N];
int dfs(int v, int par, int X) {
int res = 1;
for (auto it : g[v]) {
int to = it.F;
if (to == par) continue;
int pos = lower_bound(all(vec[it.S]), PII(X, 0)) - vec[it.S].begin() - 1;
if (pos < 0) continue;
res += dfs(to, v, (vec[it.S][pos].S ? X : vec[it.S][pos].F ));
}
return res;
}
int main() {
#ifdef krauch
freopen("input.txt", "r", stdin);
#endif
scanf("%d%d%d", &n, &m, &Q);
forn(i, 1, n - 1) {
int x, y;
scanf("%d%d", &x, &y);
g[x].eb(y, i);
g[y].eb(x, i);
}
forn(i, 1, m) {
int x;
scanf("%d", &x);
open[x] ^= 1;
vec[x].eb(i, open[x]);
}
forn(i, 1, Q) {
int x;
scanf("%d", &x);
cout << dfs(x, 0, m + 1) << "\n";
}
return 0;
}
Compilation message (stderr)
# | 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... |