답안 #73522

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
73522 2018-08-28T11:31:17 Z hamzqq9 Simurgh (IOI17_simurgh) C++14
0 / 100
3 ms 484 KB
#include "simurgh.h"
#include<bits/stdc++.h>
#define ii pair<int,int>
#define st first
#define nd second
#define pb push_back
#define iii pair<ii,int>
#define all(x) x.begin(),x.end()
#define ppb pop_back
#define ll long long
#define sz(x) ((int)x.size())
using namespace std;

int n,m,inus,ous;
int normal;
vector<int> inmst,path,ans;
int ata[505],ok[505];
vector<iii> rem,e;
vector<ii> v[505];
int flag,reach;

int bul(int x) {

	if(ata[x]==x) return x;

	return ata[x]=bul(ata[x]);

}

void finish(int w) {

	sort(all(path));

	int ptr=-1;

	int bef=0;

	vector<int> ress;

	for(int i=0;i<sz(path);i++) {

		while(ptr+1<sz(inmst) && inmst[ptr+1]<=path[i]) ptr++;

		if(bef && ok[inmst[i]]!=0) {

			continue ;

		}

		bef=max(bef,ok[inmst[i]]);

		swap(inmst[ptr],w);

		int cur=count_common_roads(inmst);

		swap(inmst[ptr],w);

		ress.pb(cur);

		if(cur>normal || (ok[inmst[i]]==1 && cur==normal)) {

			flag=1;

		}

		if(cur<normal || (ok[inmst[i]]==2 && cur==normal)) {

			flag=-1;

		}

	}

	int pr=0;

	if(flag==1) {

		for(int i=0;i<sz(path);i++) {

			if(ok[path[i]]) continue ;

			if(ress[pr]==normal) {

				ok[path[i]]=1;

				ans.pb(path[i]);

			}
			else {

				ok[path[i]]=2;

			}

			++pr;

		}

	}
	else if(flag==-1) {

		for(int i=0;i<sz(path);i++) {

			if(ok[path[i]]) continue ;

			if(ress[pr]==normal) {

				ok[path[i]]=2;

			}
			else {

				ok[path[i]]=1;
				ans.pb(path[i]);

			}

			++pr;

		}

		flag=0;

	}
	else {

		for(int i=0;i<sz(path);i++) {

			ok[path[i]]=2;

		}

	}

}

void dfs(int node,int ata,int to,int w) {

	if(reach) return ;

	if(node==to) {

		finish(w);

		reach=1;

		return ;

	}

	for(ii i:v[node]) {

		if(i.st==ata) continue ;

		path.pb(i.nd);

		dfs(i.st,node,to,w);

		path.ppb();

	}

}

void make_mst() {

	for(int i=0;i<n;i++) ata[i]=i;

	for(auto i:e) {

		if(bul(i.st.st)!=bul(i.st.nd)) {

			inmst.pb(i.nd);

			ata[bul(i.st.st)]=bul(i.st.nd);

			v[i.st.st].pb({i.st.nd,i.nd});
			v[i.st.nd].pb({i.st.st,i.nd});

		}
		else {

			rem.pb(i);

		}

	}

	sort(all(inmst));

	normal=count_common_roads(inmst);

}

std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
	
	m=sz(u);
	::n=n;

	for(int i=0;i<m;i++) {

		e.pb({{u[i],v[i]},i});

	}

	random_shuffle(all(e));

	make_mst();

	for(auto edge:rem) {

		flag=0;
		reach=0;

		dfs(edge.st.st,-1,edge.st.nd,edge.nd);

		if(flag) {

			ans.pb(edge.nd);

		}

		if(sz(ans)==n-1) break ;

	}

	for(int i=0;i<sz(inmst);i++) if(!ok[inmst[i]]) ans.pb(inmst[i]);

	return ans;

}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 248 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 248 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 248 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 484 KB correct
2 Incorrect 2 ms 484 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 248 KB WA in grader: NO
2 Halted 0 ms 0 KB -