답안 #125161

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125161 2019-07-04T19:29:38 Z Sorting Simurgh (IOI17_simurgh) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

int count_common_roads(vector<int> &r);

const int N = 507;
const int M = N * (N - 1) / 2 + 1;

mt19937 mt;

int rnd(int mod){
	return mt() % mod;
}

struct edge{
	int from, to, idx;

	edge();
	edge(int from, int to, int idx){
		this->from = from;
		this->to = to;
		this->idx = idx;
	}
};

vector<int> adj[N];
vector<edge> ev;
int m, par[N], sz[N];

void find_par(int u){
	if(u == par[u]){
		return;
	}

	find_par(par[u]);
	par[u] = par[par[u]];
}

bool unite(int u, int v){
	find_par(u);
	find_par(v);

	if(par[u] == par[v]){
		return false;
	}
	if(sz[par[u]] < sz[par[v]]){
		swap(u, v);
	}

	sz[par[u]] += sz[par[v]];
	par[par[v]] = par[u];

	return true;
}

vector<int> find_roads(int n, vector<int> u, vector<int> v){
	m = (int)u.size();

	for(int i = 0; i < m; i++){
		adj[ u[i] ].push_back(v[i]);
		adj[ v[i] ].push_back(u[i]);
		ev.push_back(edge(u[i], v[i], i));
	}

	while(true){
		for(int i = 0; i < n; i++){
			par[i] = i;
			sz[i] = 1;
		}

		random_shuffle(ev.begin(), ev.end(), rnd);
		vector<int> v;

		for(edge e: ev){
			if(unite(e.from, e.to)){
				v.push_back(e.idx);

				if(v.size() == n - 1){
					break;
				}
			}
		}

		if(count_common_roads(v) == n - 1){
			return v;
		}
	}
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:79:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(v.size() == n - 1){
        ~~~~~~~~~^~~~~~~~
/tmp/cczeu6rm.o: In function `find_roads(int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)':
simurgh.cpp:(.text+0x416): undefined reference to `count_common_roads(std::vector<int, std::allocator<int> >&)'
collect2: error: ld returned 1 exit status