Submission #335803

# Submission time Handle Problem Language Result Execution time Memory
335803 2020-12-14T03:24:09 Z ChrisT None (JOI16_ho_t3) C++17
100 / 100
240 ms 21868 KB
#include <bits/stdc++.h>
using namespace std;
const int MN = 1e5 + 5;
vector<array<int,2>> adj[MN];
vector<array<int,2>> dagadj[MN];
int indeg[MN], ed[MN*2], dist[MN];
bool exists[MN*2];
int main() { 
	int n,m,qq;
	scanf ("%d %d %d",&n,&m,&qq);
	vector<array<int,2>> edges(m+1);
	for (int i = 1; i <= m; i++) {
		scanf ("%d %d",&edges[i][0],&edges[i][1]);
		adj[edges[i][0]].push_back({edges[i][1],i});
		adj[edges[i][1]].push_back({edges[i][0],i});
	}
	memset(dist,0x3f,sizeof dist);
	queue<int> q; dist[1] = 0; q.push(1);
	while (!q.empty()) {
		int cur = q.front(); q.pop();
		for (auto &[u,i] : adj[cur]) {
			if (dist[cur] + 1 < dist[u]) {
				dist[u] = dist[cur] + 1;
				q.push(u); ed[i] = u; indeg[u] = 1;
				dagadj[cur].push_back({u,i});
			} else if (dist[cur] + 1 == dist[u]) {
				ed[i] = u; ++indeg[u]; dagadj[cur].push_back({u,i});
			}
		}
	}
	fill(exists+1,exists+m+1,true);
	int ans = n;
	for (int t = 1; t <= qq; t++) {
		int r; scanf ("%d",&r); 
		if (exists[r] && ed[r] && !(--indeg[ed[r]])) q.push(ed[r]), --ans;
		exists[r] = 0;
		while (!q.empty()) {
			int cur = q.front(); q.pop();
			for (auto &[u,i] : dagadj[cur]) {
				if (exists[i] && !(--indeg[u])) {
					--ans; q.push(u);
				}
				exists[i] = 0;
			}
		}
		printf ("%d\n",n-ans);
	}
	return 0;
}

Compilation message

2016_ho_t3.cpp: In function 'int main()':
2016_ho_t3.cpp:10:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |  scanf ("%d %d %d",&n,&m,&qq);
      |  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~
2016_ho_t3.cpp:13:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |   scanf ("%d %d",&edges[i][0],&edges[i][1]);
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2016_ho_t3.cpp:34:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |   int r; scanf ("%d",&r);
      |          ~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5484 KB Output is correct
2 Correct 4 ms 5484 KB Output is correct
3 Correct 7 ms 5612 KB Output is correct
4 Correct 5 ms 5484 KB Output is correct
5 Correct 6 ms 5484 KB Output is correct
6 Correct 5 ms 5484 KB Output is correct
7 Correct 5 ms 5484 KB Output is correct
8 Correct 4 ms 5484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5484 KB Output is correct
2 Correct 4 ms 5484 KB Output is correct
3 Correct 7 ms 5612 KB Output is correct
4 Correct 5 ms 5484 KB Output is correct
5 Correct 6 ms 5484 KB Output is correct
6 Correct 5 ms 5484 KB Output is correct
7 Correct 5 ms 5484 KB Output is correct
8 Correct 4 ms 5484 KB Output is correct
9 Correct 187 ms 18924 KB Output is correct
10 Correct 188 ms 18924 KB Output is correct
11 Correct 145 ms 18924 KB Output is correct
12 Correct 154 ms 19052 KB Output is correct
13 Correct 155 ms 19180 KB Output is correct
14 Correct 152 ms 19436 KB Output is correct
15 Correct 90 ms 15340 KB Output is correct
16 Correct 72 ms 14572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 184 ms 18924 KB Output is correct
2 Correct 175 ms 18924 KB Output is correct
3 Correct 105 ms 15708 KB Output is correct
4 Correct 164 ms 18984 KB Output is correct
5 Correct 152 ms 19436 KB Output is correct
6 Correct 155 ms 19436 KB Output is correct
7 Correct 93 ms 14572 KB Output is correct
8 Correct 77 ms 14444 KB Output is correct
9 Correct 54 ms 12124 KB Output is correct
10 Correct 45 ms 12512 KB Output is correct
11 Correct 179 ms 19436 KB Output is correct
12 Correct 189 ms 18796 KB Output is correct
13 Correct 160 ms 18412 KB Output is correct
14 Correct 192 ms 19724 KB Output is correct
15 Correct 222 ms 19164 KB Output is correct
16 Correct 190 ms 18924 KB Output is correct
17 Correct 190 ms 18924 KB Output is correct
18 Correct 133 ms 15724 KB Output is correct
19 Correct 230 ms 21868 KB Output is correct
20 Correct 187 ms 18924 KB Output is correct
21 Correct 110 ms 15084 KB Output is correct
22 Correct 111 ms 14956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5484 KB Output is correct
2 Correct 4 ms 5484 KB Output is correct
3 Correct 7 ms 5612 KB Output is correct
4 Correct 5 ms 5484 KB Output is correct
5 Correct 6 ms 5484 KB Output is correct
6 Correct 5 ms 5484 KB Output is correct
7 Correct 5 ms 5484 KB Output is correct
8 Correct 4 ms 5484 KB Output is correct
9 Correct 187 ms 18924 KB Output is correct
10 Correct 188 ms 18924 KB Output is correct
11 Correct 145 ms 18924 KB Output is correct
12 Correct 154 ms 19052 KB Output is correct
13 Correct 155 ms 19180 KB Output is correct
14 Correct 152 ms 19436 KB Output is correct
15 Correct 90 ms 15340 KB Output is correct
16 Correct 72 ms 14572 KB Output is correct
17 Correct 184 ms 18924 KB Output is correct
18 Correct 175 ms 18924 KB Output is correct
19 Correct 105 ms 15708 KB Output is correct
20 Correct 164 ms 18984 KB Output is correct
21 Correct 152 ms 19436 KB Output is correct
22 Correct 155 ms 19436 KB Output is correct
23 Correct 93 ms 14572 KB Output is correct
24 Correct 77 ms 14444 KB Output is correct
25 Correct 54 ms 12124 KB Output is correct
26 Correct 45 ms 12512 KB Output is correct
27 Correct 179 ms 19436 KB Output is correct
28 Correct 189 ms 18796 KB Output is correct
29 Correct 160 ms 18412 KB Output is correct
30 Correct 192 ms 19724 KB Output is correct
31 Correct 222 ms 19164 KB Output is correct
32 Correct 190 ms 18924 KB Output is correct
33 Correct 190 ms 18924 KB Output is correct
34 Correct 133 ms 15724 KB Output is correct
35 Correct 230 ms 21868 KB Output is correct
36 Correct 187 ms 18924 KB Output is correct
37 Correct 110 ms 15084 KB Output is correct
38 Correct 111 ms 14956 KB Output is correct
39 Correct 236 ms 21484 KB Output is correct
40 Correct 240 ms 21356 KB Output is correct
41 Correct 125 ms 16864 KB Output is correct
42 Correct 202 ms 21444 KB Output is correct
43 Correct 233 ms 21496 KB Output is correct
44 Correct 199 ms 21740 KB Output is correct
45 Correct 217 ms 21740 KB Output is correct
46 Correct 111 ms 16176 KB Output is correct
47 Correct 102 ms 15724 KB Output is correct
48 Correct 107 ms 15724 KB Output is correct
49 Correct 75 ms 13148 KB Output is correct
50 Correct 82 ms 13408 KB Output is correct
51 Correct 78 ms 13788 KB Output is correct
52 Correct 82 ms 14176 KB Output is correct
53 Correct 74 ms 13148 KB Output is correct
54 Correct 76 ms 13536 KB Output is correct