Submission #118747

# Submission time Handle Problem Language Result Execution time Memory
118747 2019-06-19T16:17:06 Z Sorting Highway Tolls (IOI18_highway) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "highway.h"

using namespace std;

long long ask(vector<int> w);
void answer(int s, int t);

const int MAXN = 1e5 + 7;

mt19937 mt();

long long n, m;
vector<int> adj[MAXN], idx[MAXN], w;
vector<pair<int, int> > e;

void dfs(int u, int pr = -1, int d = 0){
	for(int i = 0; i < adj[u].size(); i++){
		int to = adj[u][i], j = idx[u][i];

		e.push_back({d + 1, j});
		dfs(to, u, d + 1);
	}
}

void find_pair(int N, vector<int> U, vector<int> V, int A, int B){
	n = N;
	m = U.size();

	for(int 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);
	}

	long long a = A, b = B;
	long long sm = ask(w);

	dfs(0);

	sort(e.begin(), e.end());

	int l = 0, r = m;

	while(l != r){
		int mid = (l + r) / 2;

		for(int i = 0; i < m; i++){
			w[i] = 0;
		}
		for(int i = mid + 1; i <= r; i++){
			w[e[i].second] = true;
		}

		long long score = ask(w);
		score -= sm;

		if(score){
			l = mid + 1;
		}
		else{
			r = mid;
		}
	}

	answer(0, l);
}

/*
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 'void dfs(int, int, int)':
highway.cpp:18:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < adj[u].size(); i++){
                 ~~^~~~~~~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:40:22: error: call of overloaded 'ask(std::vector<int>&)' is ambiguous
  long long sm = ask(w);
                      ^
In file included from highway.cpp:2:0:
highway.h:7:11: note: candidate: long long int ask(const std::vector<int>&)
 long long ask(const std::vector<int> &w);
           ^~~
highway.cpp:6:11: note: candidate: long long int ask(std::vector<int>)
 long long ask(vector<int> w);
           ^~~
highway.cpp:58:26: error: call of overloaded 'ask(std::vector<int>&)' is ambiguous
   long long score = ask(w);
                          ^
In file included from highway.cpp:2:0:
highway.h:7:11: note: candidate: long long int ask(const std::vector<int>&)
 long long ask(const std::vector<int> &w);
           ^~~
highway.cpp:6:11: note: candidate: long long int ask(std::vector<int>)
 long long ask(vector<int> w);
           ^~~
highway.cpp:39:12: warning: unused variable 'a' [-Wunused-variable]
  long long a = A, b = B;
            ^
highway.cpp:39:19: warning: unused variable 'b' [-Wunused-variable]
  long long a = A, b = B;
                   ^