Submission #99777

# Submission time Handle Problem Language Result Execution time Memory
99777 2019-03-07T04:46:48 Z shoemakerjo Synchronization (JOI13_synchronization) C++14
0 / 100
61 ms 14656 KB
#include <bits/stdc++.h>

using namespace std;

#define maxn 200010

#define pii pair<int, int>

int N, M, Q;

vector<pii> adj[maxn]; //store the node and the value

pii ed[maxn]; //store the edges

bool isin[maxn];
int dj[maxn];

bool canreach[maxn];

void dfs(int u, int p = -1) {
	canreach[u] = true;
	for (pii vp : adj[u]) {
		if (isin[vp.second] && vp.first != p) {
			dfs(vp.first, u);
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N >> M >> Q;

	int u, v;
	for (int i = 1; i <= N-1; i++) {
		cin >> u >> v;
		adj[u].push_back(pii(v, i));
		adj[v].push_back(pii(u, i));
		ed[i] = pii(u, v);
	}

	for (int i = 1; i <= M; i++) {
		cin >> dj[i];
		isin[dj[i]] ^= true;
	}

	int rt; //the root
	cin >> rt;

	canreach[rt] = true;
	dfs(rt);

	for (int i = M; i >= 1; i--) {
		u = ed[dj[i]].first;
		v = ed[dj[i]].second;

		canreach[u] |= canreach[v];
		canreach[v] |= canreach[u];
	}

	int res = 0;
	for (int i = 1; i <= N; i++) {
		if (canreach[i]) {
			// cout << "    " << i << " reaches " << endl;
			res++;
		}
	}
	cout << res << endl;

}	
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Incorrect 6 ms 5116 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 58 ms 14656 KB Output is correct
2 Correct 61 ms 13684 KB Output is correct
3 Incorrect 51 ms 11384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 55 ms 12436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 5120 KB Output isn't correct
2 Halted 0 ms 0 KB -