Submission #118766

# Submission time Handle Problem Language Result Execution time Memory
118766 2019-06-19T16:50:24 Z Sorting Highway Tolls (IOI18_highway) C++14
0 / 100
393 ms 262148 KB
#include <bits/stdc++.h>
#include "highway.h"

using namespace std;

const int MAXN = 1e5 + 7;

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

mt19937 mt();

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

long long a, b;
long long sm;

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

		if(to == pr || used[to]){
			continue;
		}

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

int f(int u, vector<int> &V, vector<int> &U){
	e.clear();
	dfs(u);

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

	int l = 0, r = (int)e.size() - 1;

	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;
		}
	}

	if(l > r){
		return u;
	}

	int x = V[e[l].second], y = U[e[l].second];

	if(depth[x] < depth[y]){
		swap(x, y);
	}

	return x;
}



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);
	}

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

	int l = 0, r = m - 1;

	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[i] = 1;
		}

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

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

	int x, y;

	used[V[l]] = true;
	x = f(U[l], V, U);

	used[V[l]] = false;
	used[U[l]] = true;
	y = f(V[l], V, U);

	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 'void dfs(int, int, int)':
highway.cpp:24:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < adj[u].size(); i++){
                 ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5108 KB Output is correct
2 Correct 6 ms 5032 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Incorrect 6 ms 5032 KB Output is incorrect: {s, t} is wrong.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5104 KB Output is correct
2 Correct 50 ms 6052 KB Output is correct
3 Correct 221 ms 14032 KB Output is correct
4 Correct 229 ms 14156 KB Output is correct
5 Runtime error 187 ms 25316 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 6872 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5032 KB Output is correct
2 Correct 41 ms 6124 KB Output is correct
3 Correct 208 ms 12332 KB Output is correct
4 Correct 268 ms 14044 KB Output is correct
5 Incorrect 254 ms 14148 KB Output is incorrect: {s, t} is wrong.
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 393 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 351 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -