답안 #132213

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132213 2019-07-18T13:22:00 Z MoNsTeR_CuBe Simurgh (IOI17_simurgh) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "simurgh.h"
using namespace std;

vector< int > U;

int getParents(int a){
	if(U[a] == a) return a;
	else return U[a] = getParents(U[a]);
}

void Union(int a, int b){
	U[getParents(a)] = getParents(b);
}

int makeBetter(vector< tuple<int, int, int> > &golden, vector< tuple<int, int, int> > &rem, int start, int n){
	
	for(int i = 0; i < n-1; i++){
		for(int j = 0; j < n;j++){
			U[j] = j;
		}
		vector< tuple<int, int, int> > tempo;
		
		vector< int > ans;
		
		for(int j = 0; j < n-1; j++){
			if(j == i) continue;
			assert(getParents(get<0>(golden[j])) != getParents(get<1>(golden[j])));
			
			Union(get<0>(golden[j]), get<1>(golden[j]));
			tempo.push_back(golden[j]);
			ans.push_back(get<2>(golden[i]));
		}
		for(int j = 0; j < (int)rem.size(); j++){
			if(getParents(get<0>(rem[j])) == getParents(get<1>(rem[j]))) continue;
			ans.push_back(get<2>(golden[i]));
			
			int x = count_common_roads(ans);
			
			if(x > start){
				
				golden = tempo;
				golden.push_back(rem[j]);
				
				swap(rem[j], rem.back());
				rem.pop_back();
				
				rem.push_back(golden[i]);
				
				return x;
			}
			ans.pop_back();
		}
	}
	return start;
}

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
	U.resize(n);
	for(int i = 0; i < n; i++){
		U[i] = i;
	}
	
	vector< tuple<int, int, int> > golden;
	
	vector< tuple<int, int, int> > rem;
	
	for(int i = 0; i < (int)u.size(); i++){
		if(getParents(u[i]) == getParents(v[i])){
			rem.push_back(make_tuple(u[i], v[i], i));
			continue;
		} 
		
		golden.push_back(make_tuple(u[i], v[i], i));
		
		Union(u[i], v[i]);
	}
	
	int start = count_common_roads(golden);
	
	while(start < n-1){
		start = makeBetter(golden, rem, start,n);
	}
	
	vector< int > ans;
	
	for(int i = 0; i < n-1; i++){
		ans.push_back(get<2>(golden[i]));
	}
	
	return ans;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:79:39: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'std::vector<std::tuple<int, int, int> >'
  int start = count_common_roads(golden);
                                       ^
In file included from simurgh.cpp:2:0:
simurgh.h:4:5: note: in passing argument 1 of 'int count_common_roads(const std::vector<int>&)'
 int count_common_roads(const std::vector<int>& r);
     ^~~~~~~~~~~~~~~~~~