답안 #121480

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
121480 2019-06-26T14:32:47 Z Sorting 통행료 (IOI18_highway) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "highway.h"
 
using namespace std;
 
const long long MAXN = 1e5 + 7;
 
long long ask(const vector<long long> &w);
void answer(long long s, long long t);
 
mt19937 mt();
 
long long n, m;
vector<long long> adj[MAXN], idx[MAXN], w;
bool used[MAXN];

long long a, b;
long long sm;
 
vector<pair<long long, long long> > bfs(long long x){
	queue<long long> q;
 
	for(long long i = 0; i < n; i++){
		used[i] = false;
	}
 
	q.push(x);
	
	vector<pair<long long, long long> > v;
 
	while(!q.empty()){
		long long u = q.front();
		q.pop();
 
		if(used[u]){
			continue;
		}
		used[u] = true;
 
		for(long long i = 0; i < adj[u].size(); i++){
			long long to = adj[u][i];
			long long j = idx[u][i];
 
			if(!used[to]){
				q.push(to);
				v.push_back({j, to});
			}
		}
	}
 
	return v;
}

long long away(long long x, const vector<long long> &U, const vector<long long> &V){
	vector<pair<long long, long long> > v = bfs(x);
 
	while((long long)v.size() != m);

	long long l = 0, r = (long long)v.size() - 1;
 
	while(l != r){
		long long mid = (l + r) >> 1;
		 
		for(long long i = 0; i < m; i++){
			w[i] = 0;
		}

		for(long long i = 0; i <= mid; i++){
			w[ v[i].first ] = 1;
		}

		long long score = ask(w); 

		if(score == (sm / a) * b){
			r = mid;
		}
		else{
			l = mid + 1;
		}
	}

	return v[l].second;
}
 
void find_pair(long long N, vector<long long> U, vector<long long> V, long long A, long long B){
	srand(time(NULL));

	n = N;
	m = U.size();
 
	for(long long i = 0; i < m; i++){
		adj[V[i]].push_back(U[i]);
		adj[U[i]].push_back(V[i]);
 
		idx[V[i]].push_back(i);
		idx[U[i]].push_back(i);
		w.push_back(0);
	}
 
	sm = ask(w);
	a = A;
	b = B;
 
	long long l = 0, r = m - 1;
 
	while(l != r){
		long long mid = (l + r) / 2;
 
		for(long long i = 0; i < m; i++){
			w[i] = 0; 
		}
		for(long long i = mid + 1; i <= r; i++){
			w[i] = 1;
		}
 
		long long score = ask(w);
		score -= sm;
 
		if(score){
			l = mid + 1;
		}
		else{
			r = mid;
		}
	}
 
	long long x, y;
 
	x = away(U[l], U, V);
 
	y = away(x, U, V);
 
	answer(x, y);
}
/*
9 1 2
4 8
4 2
8 0
2 5
2 7
2 3
0 1
0 6
*/

Compilation message

highway.cpp: In function 'std::vector<std::pair<long long int, long long int> > bfs(long long int)':
highway.cpp:40:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(long long i = 0; i < adj[u].size(); i++){
                        ~~^~~~~~~~~~~~~~~
/tmp/cczp5hKI.o: In function `main':
grader.cpp:(.text.startup+0x125): undefined reference to `find_pair(int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, int, int)'
/tmp/cc5V30ZB.o: In function `away(long long, std::vector<long long, std::allocator<long long> > const&, std::vector<long long, std::allocator<long long> > const&)':
highway.cpp:(.text+0x495): undefined reference to `ask(std::vector<long long, std::allocator<long long> > const&)'
/tmp/cc5V30ZB.o: In function `find_pair(long long, std::vector<long long, std::allocator<long long> >, std::vector<long long, std::allocator<long long> >, long long, long long)':
highway.cpp:(.text+0x71e): undefined reference to `ask(std::vector<long long, std::allocator<long long> > const&)'
highway.cpp:(.text+0x7ce): undefined reference to `ask(std::vector<long long, std::allocator<long long> > const&)'
highway.cpp:(.text+0x946): undefined reference to `ask(std::vector<long long, std::allocator<long long> > const&)'
highway.cpp:(.text+0x9a2): undefined reference to `answer(long long, long long)'
collect2: error: ld returned 1 exit status