Submission #241753

# Submission time Handle Problem Language Result Execution time Memory
241753 2020-06-25T12:29:43 Z dsjong None (JOI16_ho_t3) C++14
100 / 100
580 ms 20324 KB
#include <bits/stdc++.h>
using namespace std;
bool vis[100005], good[200005],  queried[200005], leaf[100005], vis2[100005];
int dis[100005], root[100005], sz[100005];
pair<int, int>edges[200005];
vector<int>adj[100005], adj2[100005];
int find(int x){
	while(x!=root[x]){
		root[x]=root[root[x]];
		x=root[x];
	}
	return x;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, m, qq;
	cin>>n>>m>>qq;
	for(int i=1;i<=m;i++){
		int x, y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
		edges[i]={x, y};
	}
	queue<int>q;
	q.push(1);
	dis[1]=0;
	while(!q.empty()){
		int x=q.front();
		vis[x]=true;
		q.pop();
		for(int y:adj[x]){
			if(vis[y]) continue;
			q.push(y);
			vis[y]=true;
			dis[y]=dis[x]+1;
		}
	}
	memset(good, 0, sizeof good);
	memset(queried, 0, sizeof queried);
	for(int i=1;i<=m;i++){
		if(abs(dis[edges[i].first]-dis[edges[i].second])==1){
			good[i]=true;
		}
	}
	vector<int>queries, ans;
	while(qq--){
		int x;
		cin>>x;
		queried[x]=true;
		queries.push_back(x);
	}
	for(int i=1;i<=m;i++){
		if(!queried[i] && good[i]){
			int x=edges[i].first, y=edges[i].second;
			if(dis[y]<dis[x]) swap(x, y);
			adj2[x].push_back(y);
		}
	}
	memset(vis, false, sizeof vis);
	int cnt=1;
	q.push(1);
	vis[1]=true;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(int y:adj2[x]){
			if(vis[y]) continue;
			q.push(y);
			cnt++;
			vis[y]=true;
		}
	}
	ans.push_back(cnt);
	reverse(queries.begin(), queries.end());
	for(int i:queries){
		if(good[i]){
			int xi=edges[i].first, yi=edges[i].second;
			if(dis[yi]<dis[xi]) swap(xi, yi);
			//cout<<xi<<">>"<<yi<<endl;
			adj2[xi].push_back(yi);
			if(vis[yi] || !vis[xi]) goto hell;
			cnt++;
			q.push(yi);
			vis[yi]=true;
			while(!q.empty()){
				int x=q.front();
				q.pop();
				for(int y:adj2[x]){
					if(vis[y]) continue;
					q.push(y);
					vis[y]=true;
					cnt++;
				}
			}
		}
		hell:;
		//cout<<sz<<endl;
		ans.push_back(cnt);
	}
	ans.pop_back();
	reverse(ans.begin(), ans.end());
	for(int i:ans) cout<<n-i<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5504 KB Output is correct
2 Correct 9 ms 5632 KB Output is correct
3 Correct 9 ms 5632 KB Output is correct
4 Correct 9 ms 5504 KB Output is correct
5 Correct 9 ms 5632 KB Output is correct
6 Correct 8 ms 5504 KB Output is correct
7 Correct 8 ms 5504 KB Output is correct
8 Correct 9 ms 5504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5504 KB Output is correct
2 Correct 9 ms 5632 KB Output is correct
3 Correct 9 ms 5632 KB Output is correct
4 Correct 9 ms 5504 KB Output is correct
5 Correct 9 ms 5632 KB Output is correct
6 Correct 8 ms 5504 KB Output is correct
7 Correct 8 ms 5504 KB Output is correct
8 Correct 9 ms 5504 KB Output is correct
9 Correct 147 ms 15864 KB Output is correct
10 Correct 159 ms 16008 KB Output is correct
11 Correct 151 ms 15840 KB Output is correct
12 Correct 153 ms 15892 KB Output is correct
13 Correct 127 ms 15992 KB Output is correct
14 Correct 141 ms 16248 KB Output is correct
15 Correct 176 ms 14328 KB Output is correct
16 Correct 86 ms 14176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 15840 KB Output is correct
2 Correct 194 ms 16008 KB Output is correct
3 Correct 183 ms 13680 KB Output is correct
4 Correct 173 ms 15864 KB Output is correct
5 Correct 179 ms 16248 KB Output is correct
6 Correct 147 ms 16248 KB Output is correct
7 Correct 101 ms 14200 KB Output is correct
8 Correct 88 ms 14072 KB Output is correct
9 Correct 46 ms 11120 KB Output is correct
10 Correct 63 ms 11252 KB Output is correct
11 Correct 313 ms 17372 KB Output is correct
12 Correct 244 ms 16372 KB Output is correct
13 Correct 258 ms 16112 KB Output is correct
14 Correct 232 ms 16884 KB Output is correct
15 Correct 359 ms 17264 KB Output is correct
16 Correct 335 ms 17120 KB Output is correct
17 Correct 416 ms 18220 KB Output is correct
18 Correct 325 ms 16188 KB Output is correct
19 Correct 533 ms 20312 KB Output is correct
20 Correct 414 ms 18284 KB Output is correct
21 Correct 194 ms 15092 KB Output is correct
22 Correct 186 ms 15092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5504 KB Output is correct
2 Correct 9 ms 5632 KB Output is correct
3 Correct 9 ms 5632 KB Output is correct
4 Correct 9 ms 5504 KB Output is correct
5 Correct 9 ms 5632 KB Output is correct
6 Correct 8 ms 5504 KB Output is correct
7 Correct 8 ms 5504 KB Output is correct
8 Correct 9 ms 5504 KB Output is correct
9 Correct 147 ms 15864 KB Output is correct
10 Correct 159 ms 16008 KB Output is correct
11 Correct 151 ms 15840 KB Output is correct
12 Correct 153 ms 15892 KB Output is correct
13 Correct 127 ms 15992 KB Output is correct
14 Correct 141 ms 16248 KB Output is correct
15 Correct 176 ms 14328 KB Output is correct
16 Correct 86 ms 14176 KB Output is correct
17 Correct 162 ms 15840 KB Output is correct
18 Correct 194 ms 16008 KB Output is correct
19 Correct 183 ms 13680 KB Output is correct
20 Correct 173 ms 15864 KB Output is correct
21 Correct 179 ms 16248 KB Output is correct
22 Correct 147 ms 16248 KB Output is correct
23 Correct 101 ms 14200 KB Output is correct
24 Correct 88 ms 14072 KB Output is correct
25 Correct 46 ms 11120 KB Output is correct
26 Correct 63 ms 11252 KB Output is correct
27 Correct 313 ms 17372 KB Output is correct
28 Correct 244 ms 16372 KB Output is correct
29 Correct 258 ms 16112 KB Output is correct
30 Correct 232 ms 16884 KB Output is correct
31 Correct 359 ms 17264 KB Output is correct
32 Correct 335 ms 17120 KB Output is correct
33 Correct 416 ms 18220 KB Output is correct
34 Correct 325 ms 16188 KB Output is correct
35 Correct 533 ms 20312 KB Output is correct
36 Correct 414 ms 18284 KB Output is correct
37 Correct 194 ms 15092 KB Output is correct
38 Correct 186 ms 15092 KB Output is correct
39 Correct 580 ms 20000 KB Output is correct
40 Correct 534 ms 19816 KB Output is correct
41 Correct 363 ms 16620 KB Output is correct
42 Correct 566 ms 19952 KB Output is correct
43 Correct 508 ms 19952 KB Output is correct
44 Correct 519 ms 20204 KB Output is correct
45 Correct 511 ms 20324 KB Output is correct
46 Correct 297 ms 16472 KB Output is correct
47 Correct 263 ms 16280 KB Output is correct
48 Correct 257 ms 16112 KB Output is correct
49 Correct 226 ms 12844 KB Output is correct
50 Correct 214 ms 12524 KB Output is correct
51 Correct 223 ms 13484 KB Output is correct
52 Correct 229 ms 13420 KB Output is correct
53 Correct 216 ms 12908 KB Output is correct
54 Correct 227 ms 12656 KB Output is correct