Submission #757865

# Submission time Handle Problem Language Result Execution time Memory
757865 2023-06-13T20:44:33 Z alexander707070 Simurgh (IOI17_simurgh) C++14
51 / 100
216 ms 4104 KB
#include<bits/stdc++.h>
#include "simurgh.h"
#define MAXN 507
#define MAXM 300007
using namespace std;
 
int n,m,a[MAXM],b[MAXM],res[MAXM],t,good;
vector< pair<int,int> > vv[MAXN];
bool li[MAXN];
vector<int> tree,ask,g[MAXN],ans;
int curr,where[MAXN],maxres;
bool golden[MAXM],checked[MAXM],first;
int dsu[MAXN];

int root(int x){
	if(dsu[x]==x)return x;
	dsu[x]=root(dsu[x]);
	return dsu[x];
}
 
void dfs(int x){
	li[x]=true;
	for(int i=0;i<vv[x].size();i++){
		if(li[vv[x][i].first])continue;
 
		tree.push_back(vv[x][i].second);
		dfs(vv[x][i].first);
	}
}
 
void comp(int x,int p,int id){
	where[x]=id;
	for(int i=0;i<g[x].size();i++){
		if(g[x][i]==p)continue;
		comp(g[x][i],x,id);
	}
}
 
vector<int> find_roads(int N,vector<int> from,vector<int> to){
	n=N; m=int(from.size());

	for(int i=0;i<n;i++){
		dsu[i]=i;
	}
 
	for(int i=0;i<m;i++){
		a[i]=from[i]; b[i]=to[i];
 
		vv[a[i]].push_back({b[i],i});
		vv[b[i]].push_back({a[i],i});
	}

	for(int i=0;i<n;i++){
		random_shuffle(vv[i].begin(),vv[i].end());
	}
 
	dfs(0);
	random_shuffle(tree.begin(),tree.end());
	
	for(int i=0;i<n-1;i++){
		for(int f=0;f<n;f++)g[f].clear();
		ask.clear();
 
		for(int f=0;f<n-1;f++){
			if(i==f)continue;
 
			ask.push_back(tree[f]);
			g[a[tree[f]]].push_back(b[tree[f]]);
			g[b[tree[f]]].push_back(a[tree[f]]);
		}
 
		comp(a[tree[i]],-1,1);
		comp(b[tree[i]],-1,2);

 
		maxres=0; first=true; good=-1;
		for(int f=0;f<m;f++){
			res[f]=0;
			if(where[a[f]]!=where[b[f]] and ((root(a[f])!=root(b[f]) and !checked[f]) or (first and golden[f]))){
				if(root(a[f])==root(b[f]))first=false;

				ask.push_back(f);
				res[f]=count_common_roads(ask);

				if(res[f]>maxres and maxres>0)good=res[f];

				if(res[f]==good){
					golden[f]=true;
					dsu[root(a[f])]=root(b[f]);
				}

				maxres=max(maxres,res[f]);
				ask.pop_back(); checked[f]=true;
			}
		}
 
		for(int f=0;f<m;f++){
			if(where[a[f]]!=where[b[f]] and res[f]==maxres){
				golden[f]=true;
				dsu[root(a[f])]=root(b[f]);
			}
		}
	}
 
	for(int i=0;i<m;i++){
		if(golden[i]){
			ans.push_back(i);
		}
	}
 
	return ans;
}

Compilation message

simurgh.cpp: In function 'void dfs(int)':
simurgh.cpp:23: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]
   23 |  for(int i=0;i<vv[x].size();i++){
      |              ~^~~~~~~~~~~~~
simurgh.cpp: In function 'void comp(int, int, int)':
simurgh.cpp:33:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |  for(int i=0;i<g[x].size();i++){
      |              ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB correct
2 Correct 0 ms 340 KB correct
3 Correct 0 ms 340 KB correct
4 Correct 1 ms 340 KB correct
5 Correct 0 ms 340 KB correct
6 Correct 0 ms 340 KB correct
7 Correct 1 ms 340 KB correct
8 Correct 1 ms 340 KB correct
9 Correct 1 ms 340 KB correct
10 Correct 1 ms 340 KB correct
11 Correct 1 ms 340 KB correct
12 Correct 0 ms 340 KB correct
13 Correct 0 ms 340 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB correct
2 Correct 0 ms 340 KB correct
3 Correct 0 ms 340 KB correct
4 Correct 1 ms 340 KB correct
5 Correct 0 ms 340 KB correct
6 Correct 0 ms 340 KB correct
7 Correct 1 ms 340 KB correct
8 Correct 1 ms 340 KB correct
9 Correct 1 ms 340 KB correct
10 Correct 1 ms 340 KB correct
11 Correct 1 ms 340 KB correct
12 Correct 0 ms 340 KB correct
13 Correct 0 ms 340 KB correct
14 Correct 3 ms 340 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 340 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 2 ms 340 KB correct
20 Correct 2 ms 340 KB correct
21 Correct 2 ms 340 KB correct
22 Correct 2 ms 340 KB correct
23 Correct 2 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 340 KB correct
26 Correct 1 ms 340 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 340 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 2 ms 340 KB correct
32 Correct 2 ms 340 KB correct
33 Correct 2 ms 340 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB correct
2 Correct 0 ms 340 KB correct
3 Correct 0 ms 340 KB correct
4 Correct 1 ms 340 KB correct
5 Correct 0 ms 340 KB correct
6 Correct 0 ms 340 KB correct
7 Correct 1 ms 340 KB correct
8 Correct 1 ms 340 KB correct
9 Correct 1 ms 340 KB correct
10 Correct 1 ms 340 KB correct
11 Correct 1 ms 340 KB correct
12 Correct 0 ms 340 KB correct
13 Correct 0 ms 340 KB correct
14 Correct 3 ms 340 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 340 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 2 ms 340 KB correct
20 Correct 2 ms 340 KB correct
21 Correct 2 ms 340 KB correct
22 Correct 2 ms 340 KB correct
23 Correct 2 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 340 KB correct
26 Correct 1 ms 340 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 340 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 2 ms 340 KB correct
32 Correct 2 ms 340 KB correct
33 Correct 2 ms 340 KB correct
34 Correct 207 ms 1776 KB correct
35 Correct 212 ms 1932 KB correct
36 Correct 148 ms 1624 KB correct
37 Correct 11 ms 468 KB correct
38 Correct 216 ms 1964 KB correct
39 Correct 169 ms 1816 KB correct
40 Correct 137 ms 1620 KB correct
41 Correct 188 ms 2008 KB correct
42 Correct 181 ms 1956 KB correct
43 Correct 100 ms 1364 KB correct
44 Correct 75 ms 980 KB correct
45 Correct 93 ms 1136 KB correct
46 Correct 66 ms 996 KB correct
47 Correct 31 ms 596 KB correct
48 Correct 5 ms 340 KB correct
49 Correct 10 ms 468 KB correct
50 Correct 27 ms 672 KB correct
51 Correct 93 ms 1148 KB correct
52 Correct 82 ms 1000 KB correct
53 Correct 68 ms 1084 KB correct
54 Correct 97 ms 1364 KB correct
55 Correct 103 ms 1168 KB correct
56 Correct 105 ms 1160 KB correct
57 Correct 93 ms 1168 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB correct
2 Correct 0 ms 340 KB correct
3 Incorrect 103 ms 4104 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB correct
2 Correct 0 ms 340 KB correct
3 Correct 0 ms 340 KB correct
4 Correct 1 ms 340 KB correct
5 Correct 0 ms 340 KB correct
6 Correct 0 ms 340 KB correct
7 Correct 1 ms 340 KB correct
8 Correct 1 ms 340 KB correct
9 Correct 1 ms 340 KB correct
10 Correct 1 ms 340 KB correct
11 Correct 1 ms 340 KB correct
12 Correct 0 ms 340 KB correct
13 Correct 0 ms 340 KB correct
14 Correct 3 ms 340 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 340 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 2 ms 340 KB correct
20 Correct 2 ms 340 KB correct
21 Correct 2 ms 340 KB correct
22 Correct 2 ms 340 KB correct
23 Correct 2 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 340 KB correct
26 Correct 1 ms 340 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 340 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 2 ms 340 KB correct
32 Correct 2 ms 340 KB correct
33 Correct 2 ms 340 KB correct
34 Correct 207 ms 1776 KB correct
35 Correct 212 ms 1932 KB correct
36 Correct 148 ms 1624 KB correct
37 Correct 11 ms 468 KB correct
38 Correct 216 ms 1964 KB correct
39 Correct 169 ms 1816 KB correct
40 Correct 137 ms 1620 KB correct
41 Correct 188 ms 2008 KB correct
42 Correct 181 ms 1956 KB correct
43 Correct 100 ms 1364 KB correct
44 Correct 75 ms 980 KB correct
45 Correct 93 ms 1136 KB correct
46 Correct 66 ms 996 KB correct
47 Correct 31 ms 596 KB correct
48 Correct 5 ms 340 KB correct
49 Correct 10 ms 468 KB correct
50 Correct 27 ms 672 KB correct
51 Correct 93 ms 1148 KB correct
52 Correct 82 ms 1000 KB correct
53 Correct 68 ms 1084 KB correct
54 Correct 97 ms 1364 KB correct
55 Correct 103 ms 1168 KB correct
56 Correct 105 ms 1160 KB correct
57 Correct 93 ms 1168 KB correct
58 Correct 0 ms 340 KB correct
59 Correct 0 ms 340 KB correct
60 Incorrect 103 ms 4104 KB WA in grader: NO
61 Halted 0 ms 0 KB -