Submission #612619

# Submission time Handle Problem Language Result Execution time Memory
612619 2022-07-29T18:22:08 Z chirathnirodha Simurgh (IOI17_simurgh) C++17
51 / 100
182 ms 6516 KB
#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define P push 
#define I insert 
#define F first 
#define S second

int n,m;
int ev[500][500];
vector<pair<int,int> > ed[500];
vector<pair<int,int> > alled;
int link[200000];
int royal[200000];
int find(int x){
	if(link[x]==x)return x;
	else return find(link[x]);
}
void func(int x){
	int parent[n];memset(parent,-1,sizeof(parent));
	vector<int> g;
	int uni[n];
	for(int h=0;h<n;h++){
		if(parent[h]!=-1 || h==x)continue;
		uni[h]=h;
		queue<int> q;q.P(h);
		parent[h]=h;
		while(!q.empty()){
			int c=q.front();q.pop();
			uni[c]=h;
			for(int i=0;i<ed[c].size();i++){
				int y=ed[c][i].F;
				if(parent[y]!=-1 || y==x)continue;
				parent[y]=c;
				g.PB(ed[c][i].S);
				q.P(y);
			}
		}
	}
	vector<pair<int,int> > v[n];
	for(int i=0;i<ed[x].size();i++){
		int y=ed[x][i].F,z=ed[x][i].S;
		v[uni[y]].PB(MP(royal[find(z)],z));
	}
	for(int i=0;i<n;i++){
		if(v[i].size()==0)continue;
		sort(v[i].begin(),v[i].end());
		g.PB(v[i].back().S);
	}

	int inival=count_common_roads(g);
	if(inival==n-1)for(int i=0;i<n-1;i++)royal[find(g[i])]=1;
	if(inival==0)for(int i=0;i<n-1;i++)royal[find(g[i])]=0;

	for(int i=0;i<n;i++){
		if(v[i].size()<1)continue;

		vector<int> ng;
		int iniadd=v[i].back().S;
		for(int j=0;j<n-1;j++)if(g[j]!=iniadd)ng.PB(g[j]);

		if(v[i].size()==1)royal[find(iniadd)]=1;

		for(int j=0;j<v[i].size()-1;j++){

			int ind=v[i][j].S;
			int lini=find(iniadd);int lcur=find(ind);
			if(royal[lcur]!=-1)break;
			int y=alled[ind].F;if(y==x)alled[ind].S;

			ng.PB(ind);
			int val=count_common_roads(ng);
			ng.pop_back();
			
			if(val==inival){
				link[lcur]=lini;
			}
			else if(val>inival){
				royal[lini]=0;
				royal[lcur]=1;
			}
			else {
				royal[lcur]=0;
				royal[lini]=1;
			}
		}
	}
	return;
} 
vector<int> find_roads(int N, vector<int> u, vector<int> v) {
	n=N;m=u.size();
	for(int i=0;i<m;i++){
		alled.PB(MP(u[i],v[i]));
		ev[u[i]][v[i]]=ev[v[i]][u[i]]=i;
		ed[u[i]].PB(MP(v[i],i));
		ed[v[i]].PB(MP(u[i],i));
	}

	for(int i=0;i<m;i++)link[i]=i;
	memset(royal,-1,sizeof(royal));
	for(int i=0;i<n;i++)func(i);
	vector<int> ans;
	for(int i=0;i<m;i++)if(royal[find(i)]==1)ans.PB(i);
	return ans;
}

Compilation message

simurgh.cpp: In function 'void func(int)':
simurgh.cpp:33:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |    for(int i=0;i<ed[c].size();i++){
      |                ~^~~~~~~~~~~~~
simurgh.cpp:43:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for(int i=0;i<ed[x].size();i++){
      |              ~^~~~~~~~~~~~~
simurgh.cpp:66:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |   for(int j=0;j<v[i].size()-1;j++){
      |               ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB correct
2 Correct 1 ms 1108 KB correct
3 Correct 1 ms 1108 KB correct
4 Correct 1 ms 1100 KB correct
5 Correct 1 ms 1100 KB correct
6 Correct 1 ms 1092 KB correct
7 Correct 1 ms 1108 KB correct
8 Correct 1 ms 1108 KB correct
9 Correct 1 ms 1108 KB correct
10 Correct 1 ms 1108 KB correct
11 Correct 1 ms 1108 KB correct
12 Correct 1 ms 1108 KB correct
13 Correct 1 ms 1096 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB correct
2 Correct 1 ms 1108 KB correct
3 Correct 1 ms 1108 KB correct
4 Correct 1 ms 1100 KB correct
5 Correct 1 ms 1100 KB correct
6 Correct 1 ms 1092 KB correct
7 Correct 1 ms 1108 KB correct
8 Correct 1 ms 1108 KB correct
9 Correct 1 ms 1108 KB correct
10 Correct 1 ms 1108 KB correct
11 Correct 1 ms 1108 KB correct
12 Correct 1 ms 1108 KB correct
13 Correct 1 ms 1096 KB correct
14 Correct 3 ms 1236 KB correct
15 Correct 3 ms 1236 KB correct
16 Correct 3 ms 1228 KB correct
17 Correct 3 ms 1236 KB correct
18 Correct 2 ms 1236 KB correct
19 Correct 3 ms 1236 KB correct
20 Correct 3 ms 1236 KB correct
21 Correct 3 ms 1236 KB correct
22 Correct 2 ms 1236 KB correct
23 Correct 2 ms 1224 KB correct
24 Correct 2 ms 1236 KB correct
25 Correct 1 ms 1108 KB correct
26 Correct 2 ms 1236 KB correct
27 Correct 2 ms 1224 KB correct
28 Correct 1 ms 1108 KB correct
29 Correct 1 ms 1108 KB correct
30 Correct 2 ms 1236 KB correct
31 Correct 2 ms 1236 KB correct
32 Correct 2 ms 1236 KB correct
33 Correct 2 ms 1236 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB correct
2 Correct 1 ms 1108 KB correct
3 Correct 1 ms 1108 KB correct
4 Correct 1 ms 1100 KB correct
5 Correct 1 ms 1100 KB correct
6 Correct 1 ms 1092 KB correct
7 Correct 1 ms 1108 KB correct
8 Correct 1 ms 1108 KB correct
9 Correct 1 ms 1108 KB correct
10 Correct 1 ms 1108 KB correct
11 Correct 1 ms 1108 KB correct
12 Correct 1 ms 1108 KB correct
13 Correct 1 ms 1096 KB correct
14 Correct 3 ms 1236 KB correct
15 Correct 3 ms 1236 KB correct
16 Correct 3 ms 1228 KB correct
17 Correct 3 ms 1236 KB correct
18 Correct 2 ms 1236 KB correct
19 Correct 3 ms 1236 KB correct
20 Correct 3 ms 1236 KB correct
21 Correct 3 ms 1236 KB correct
22 Correct 2 ms 1236 KB correct
23 Correct 2 ms 1224 KB correct
24 Correct 2 ms 1236 KB correct
25 Correct 1 ms 1108 KB correct
26 Correct 2 ms 1236 KB correct
27 Correct 2 ms 1224 KB correct
28 Correct 1 ms 1108 KB correct
29 Correct 1 ms 1108 KB correct
30 Correct 2 ms 1236 KB correct
31 Correct 2 ms 1236 KB correct
32 Correct 2 ms 1236 KB correct
33 Correct 2 ms 1236 KB correct
34 Correct 176 ms 3188 KB correct
35 Correct 178 ms 3080 KB correct
36 Correct 115 ms 2760 KB correct
37 Correct 12 ms 1668 KB correct
38 Correct 182 ms 3152 KB correct
39 Correct 150 ms 2896 KB correct
40 Correct 119 ms 2756 KB correct
41 Correct 173 ms 3152 KB correct
42 Correct 177 ms 3280 KB correct
43 Correct 90 ms 2476 KB correct
44 Correct 76 ms 2260 KB correct
45 Correct 87 ms 2516 KB correct
46 Correct 68 ms 2264 KB correct
47 Correct 30 ms 1892 KB correct
48 Correct 6 ms 1604 KB correct
49 Correct 11 ms 1620 KB correct
50 Correct 31 ms 1876 KB correct
51 Correct 87 ms 2388 KB correct
52 Correct 75 ms 2264 KB correct
53 Correct 62 ms 2280 KB correct
54 Correct 90 ms 2516 KB correct
55 Correct 88 ms 2392 KB correct
56 Correct 85 ms 2388 KB correct
57 Correct 86 ms 2388 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1096 KB correct
2 Correct 1 ms 1108 KB correct
3 Incorrect 156 ms 6516 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB correct
2 Correct 1 ms 1108 KB correct
3 Correct 1 ms 1108 KB correct
4 Correct 1 ms 1100 KB correct
5 Correct 1 ms 1100 KB correct
6 Correct 1 ms 1092 KB correct
7 Correct 1 ms 1108 KB correct
8 Correct 1 ms 1108 KB correct
9 Correct 1 ms 1108 KB correct
10 Correct 1 ms 1108 KB correct
11 Correct 1 ms 1108 KB correct
12 Correct 1 ms 1108 KB correct
13 Correct 1 ms 1096 KB correct
14 Correct 3 ms 1236 KB correct
15 Correct 3 ms 1236 KB correct
16 Correct 3 ms 1228 KB correct
17 Correct 3 ms 1236 KB correct
18 Correct 2 ms 1236 KB correct
19 Correct 3 ms 1236 KB correct
20 Correct 3 ms 1236 KB correct
21 Correct 3 ms 1236 KB correct
22 Correct 2 ms 1236 KB correct
23 Correct 2 ms 1224 KB correct
24 Correct 2 ms 1236 KB correct
25 Correct 1 ms 1108 KB correct
26 Correct 2 ms 1236 KB correct
27 Correct 2 ms 1224 KB correct
28 Correct 1 ms 1108 KB correct
29 Correct 1 ms 1108 KB correct
30 Correct 2 ms 1236 KB correct
31 Correct 2 ms 1236 KB correct
32 Correct 2 ms 1236 KB correct
33 Correct 2 ms 1236 KB correct
34 Correct 176 ms 3188 KB correct
35 Correct 178 ms 3080 KB correct
36 Correct 115 ms 2760 KB correct
37 Correct 12 ms 1668 KB correct
38 Correct 182 ms 3152 KB correct
39 Correct 150 ms 2896 KB correct
40 Correct 119 ms 2756 KB correct
41 Correct 173 ms 3152 KB correct
42 Correct 177 ms 3280 KB correct
43 Correct 90 ms 2476 KB correct
44 Correct 76 ms 2260 KB correct
45 Correct 87 ms 2516 KB correct
46 Correct 68 ms 2264 KB correct
47 Correct 30 ms 1892 KB correct
48 Correct 6 ms 1604 KB correct
49 Correct 11 ms 1620 KB correct
50 Correct 31 ms 1876 KB correct
51 Correct 87 ms 2388 KB correct
52 Correct 75 ms 2264 KB correct
53 Correct 62 ms 2280 KB correct
54 Correct 90 ms 2516 KB correct
55 Correct 88 ms 2392 KB correct
56 Correct 85 ms 2388 KB correct
57 Correct 86 ms 2388 KB correct
58 Correct 1 ms 1096 KB correct
59 Correct 1 ms 1108 KB correct
60 Incorrect 156 ms 6516 KB WA in grader: NO
61 Halted 0 ms 0 KB -