Submission #1078162

# Submission time Handle Problem Language Result Execution time Memory
1078162 2024-08-27T13:27:07 Z noyancanturk Simurgh (IOI17_simurgh) C++17
49 / 100
125 ms 4364 KB
#include "simurgh.h"

#include<bits/stdc++.h>
using namespace std;

#define pb push_back

const int lim=510;

int n;
int v[lim][lim];
int edgecnt[lim],p[lim];

struct{
	int par[lim],sz[lim];
	void init(){
		for(int i=0;i<n;i++)par[i]=i,sz[i]=1;
	}
	int find(int i){
		if(i==par[i])return i;
		return par[i]=find(par[i]);
	}
	bool unite(int i,int j){
		i=find(i),j=find(j);
		if(i^j){
			par[i]=j;
			sz[j]+=sz[i];
			return 1;
		}
		return 0;
	}
}dsu;

void findedgecnt(int node){
	vector<int>r;
	for(int i=0;i<n;i++){
		if(i==node)continue;
		r.pb(v[node][i]);
	}
	edgecnt[node]=count_common_roads(r);
	if(node)edgecnt[node]--;
}

int lineadd(int node){
	vector<int>r;
	for(int i=1;i+1<n;i++){
		r.pb(v[i][i+1]);
	}
	r.pb(v[0][node]);
	return count_common_roads(r);
}

vector<int>legit;

vector<int> find_roads(int N, vector<int> u1, vector<int> u2) {
	n=N;
	legit.clear();
	for(int i=0;i<n;i++)p[i]=-1;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			v[i][j]=-1;
	int m=u1.size();
	for(int i=0;i<m;i++){
		v[u1[i]][u2[i]]=i;
		v[u2[i]][u1[i]]=i;
	}
	if(m==n*(n-1)/2){
		cerr<<"here??\n";
		for(int i=0;i<n;i++)findedgecnt(i);
		int best=lineadd(1);
		vector<int>toad;
		toad.pb(1);
		for(int i=2;i<n;i++){
			int cnt=lineadd(i);
			if(cnt==best){
				toad.pb(i);
			}else if(best<cnt){
				best=cnt;
				toad.clear();
				toad.pb(i);
			}
		}
		vector<int>q;
		for(int i:toad){
			q.pb(i);
			p[i]=0;
			legit.pb(v[0][i]);
		}
		while(q.size()){
			int node=q.back();
			q.pop_back();
			vector<int>dudes;
			for(int i=1;i<n;i++){
				if(p[i]==-1)dudes.pb(i);
			}
			int tt=-1;
			vector<int>found;
			while(edgecnt[node]){
				int l=tt+2,r=dudes.size()-1,ans=tt+1;
				while(l<=r){
					int mid=(l+r)>>1;
					vector<int>wow=legit;
					for(int i=0;i<mid;i++){
						wow.pb(v[0][dudes[i]]);
					}
					for(int i=mid;i<dudes.size();i++){
						wow.pb(v[node][dudes[i]]);
					}
					int cnt=count_common_roads(wow)-legit.size();
					if(cnt==edgecnt[node]){
						ans=mid;
						l=mid+1;
					}else{
						r=mid-1;
					}
				}
				found.pb(dudes[ans]);
				edgecnt[node]--;
				tt=ans;
			}
			for(int i:found){
				p[i]=node;
				legit.pb(v[node][i]);
				q.pb(i);
			}
		}
		return legit;
	}
	for(int node=0;node<n;node++){
		dsu.init();
		vector<int>well;
		for(int i=0;i<n;i++){
			if(i==node)continue;
			for(int j=0;j<n;j++){
				if(j==node)continue;
				if(v[i][j]!=-1&&dsu.unite(i,j)){
					well.pb(v[i][j]);
				}
			}
		}
		vector<int> comps[n]{};
		for(int i=0;i<n;i++){
			comps[dsu.find(i)].pb(i);
		}
		for(int cur=0;cur<n;cur++){
			if(!comps[cur].size()||cur==node)continue;
			vector<int>toask=well;
			for(int i=0;i<n;i++){
				if(i==cur||i==node||!comps[i].size())continue;
				for(int j:comps[i]){
					if(v[node][j]!=-1){
						toask.pb(v[node][j]);
						break;
					}
				}
			}
			int best=-1;
			vector<int>topush;
			for(int i:comps[cur]){
				if(v[node][i]!=-1){
					toask.pb(v[node][i]);
					int cnt=count_common_roads(toask);
					if(best<cnt){
						topush.clear();
						best=cnt;
					}
					if(best==cnt&&node<i){
						topush.pb(v[node][i]);
					}
					toask.pop_back();
				}
			}
			for(int i:topush)legit.pb(i);
		}
	}
	return legit;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:106:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |      for(int i=mid;i<dudes.size();i++){
      |                    ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 344 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 0 ms 348 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 344 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 0 ms 348 KB correct
14 Correct 1 ms 348 KB correct
15 Correct 1 ms 348 KB correct
16 Correct 1 ms 344 KB correct
17 Correct 2 ms 348 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 2 ms 348 KB correct
20 Correct 2 ms 348 KB correct
21 Correct 2 ms 348 KB correct
22 Correct 2 ms 432 KB correct
23 Correct 2 ms 344 KB correct
24 Correct 1 ms 348 KB correct
25 Correct 1 ms 348 KB correct
26 Correct 2 ms 348 KB correct
27 Correct 2 ms 348 KB correct
28 Correct 1 ms 344 KB correct
29 Correct 1 ms 348 KB correct
30 Correct 1 ms 348 KB correct
31 Correct 2 ms 348 KB correct
32 Correct 2 ms 448 KB correct
33 Correct 2 ms 348 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 344 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 0 ms 348 KB correct
14 Correct 1 ms 348 KB correct
15 Correct 1 ms 348 KB correct
16 Correct 1 ms 344 KB correct
17 Correct 2 ms 348 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 2 ms 348 KB correct
20 Correct 2 ms 348 KB correct
21 Correct 2 ms 348 KB correct
22 Correct 2 ms 432 KB correct
23 Correct 2 ms 344 KB correct
24 Correct 1 ms 348 KB correct
25 Correct 1 ms 348 KB correct
26 Correct 2 ms 348 KB correct
27 Correct 2 ms 348 KB correct
28 Correct 1 ms 344 KB correct
29 Correct 1 ms 348 KB correct
30 Correct 1 ms 348 KB correct
31 Correct 2 ms 348 KB correct
32 Correct 2 ms 448 KB correct
33 Correct 2 ms 348 KB correct
34 Correct 10 ms 1372 KB correct
35 Incorrect 125 ms 1620 KB WA in grader: NO
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 29 ms 3128 KB correct
4 Correct 47 ms 4364 KB correct
5 Correct 45 ms 4184 KB correct
6 Correct 46 ms 4188 KB correct
7 Correct 42 ms 4360 KB correct
8 Correct 44 ms 4188 KB correct
9 Correct 45 ms 4184 KB correct
10 Correct 49 ms 4184 KB correct
11 Correct 45 ms 4188 KB correct
12 Correct 47 ms 4184 KB correct
13 Correct 0 ms 348 KB correct
14 Correct 47 ms 4352 KB correct
15 Correct 46 ms 4184 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 0 ms 344 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 0 ms 348 KB correct
14 Correct 1 ms 348 KB correct
15 Correct 1 ms 348 KB correct
16 Correct 1 ms 344 KB correct
17 Correct 2 ms 348 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 2 ms 348 KB correct
20 Correct 2 ms 348 KB correct
21 Correct 2 ms 348 KB correct
22 Correct 2 ms 432 KB correct
23 Correct 2 ms 344 KB correct
24 Correct 1 ms 348 KB correct
25 Correct 1 ms 348 KB correct
26 Correct 2 ms 348 KB correct
27 Correct 2 ms 348 KB correct
28 Correct 1 ms 344 KB correct
29 Correct 1 ms 348 KB correct
30 Correct 1 ms 348 KB correct
31 Correct 2 ms 348 KB correct
32 Correct 2 ms 448 KB correct
33 Correct 2 ms 348 KB correct
34 Correct 10 ms 1372 KB correct
35 Incorrect 125 ms 1620 KB WA in grader: NO
36 Halted 0 ms 0 KB -