Submission #100877

# Submission time Handle Problem Language Result Execution time Memory
100877 2019-03-15T01:40:00 Z E869120 Synchronization (JOI13_synchronization) C++14
30 / 100
8000 ms 18488 KB
#include <bits/stdc++.h>
using namespace std;

int N, M, Q, A[100009], B[100009], uses[100009]; bool used[100009];
vector<pair<int, int>> L[100009]; vector<pair<int, int>>G[100009];

void dfs(int pos, int dep) {
	used[pos] = true;
	for (int i = 0; i < (int)G[pos].size(); i++) {
		int to = G[pos][i].first, id = G[pos][i].second;
		if (used[to] == true) continue;
		
		int pos1 = lower_bound(L[id].begin(), L[id].end(), make_pair(dep + 1, 0)) - L[id].begin(); pos1--;
		int r = -1;
		if (pos1 >= 0 && dep <= L[id][pos1].second) r = dep;
		else if (pos1 >= 0) r = L[id][pos1].second;
		if (r >= 0) dfs(to, r);
	}
}

int main() {
	scanf("%d%d%d", &N, &M, &Q);
	for (int i = 1; i <= N - 1; i++) scanf("%d%d", &A[i],&B[i]);
	for (int i = 1; i <= N - 1; i++) uses[i] = -1;
	for (int i = 1; i <= N - 1; i++) { G[A[i]].push_back(make_pair(B[i], i)); G[B[i]].push_back(make_pair(A[i], i)); }
	
	for (int i = 1; i <= M; i++) {
		int p; scanf("%d", &p);
		if (uses[p] == -1) uses[p] = i;
		else { L[p].push_back(make_pair(uses[p], i - 1)); uses[p] = -1; }
	}
	for (int i = 1; i <= N - 1; i++) { if (uses[i] >= 1) L[i].push_back(make_pair(uses[i], M)); }
	
	for (int i = 1; i <= Q; i++) {
		int c; scanf("%d", &c);
		for (int j = 1; j <= N; j++) used[j] = false;
		dfs(c, M);
		int cnts = 0; for (int j = 1; j <= N; j++) { if(used[j] == true) cnts++; }
		printf("%d\n", cnts);
	}
	return 0;
}

Compilation message

synchronization.cpp: In function 'int main()':
synchronization.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &N, &M, &Q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:23:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= N - 1; i++) scanf("%d%d", &A[i],&B[i]);
                                   ~~~~~^~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:28:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int p; scanf("%d", &p);
          ~~~~~^~~~~~~~~~
synchronization.cpp:35:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int c; scanf("%d", &c);
          ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5120 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 8 ms 4988 KB Output is correct
4 Correct 8 ms 4992 KB Output is correct
5 Correct 6 ms 4992 KB Output is correct
6 Correct 7 ms 5120 KB Output is correct
7 Correct 19 ms 6016 KB Output is correct
8 Correct 17 ms 6016 KB Output is correct
9 Correct 17 ms 6016 KB Output is correct
10 Correct 160 ms 15204 KB Output is correct
11 Correct 153 ms 15296 KB Output is correct
12 Correct 104 ms 14456 KB Output is correct
13 Correct 116 ms 14956 KB Output is correct
14 Correct 126 ms 14920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 17648 KB Output is correct
2 Correct 72 ms 16544 KB Output is correct
3 Correct 99 ms 18488 KB Output is correct
4 Correct 66 ms 17884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 4992 KB Output is correct
5 Correct 8 ms 5120 KB Output is correct
6 Correct 10 ms 5120 KB Output is correct
7 Correct 117 ms 6168 KB Output is correct
8 Execution timed out 8086 ms 15536 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 8006 ms 15512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 8 ms 4992 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 4992 KB Output is correct
5 Correct 12 ms 5120 KB Output is correct
6 Correct 218 ms 6136 KB Output is correct
7 Execution timed out 8061 ms 16112 KB Time limit exceeded
8 Halted 0 ms 0 KB -