Submission #594826

#TimeUsernameProblemLanguageResultExecution timeMemory
594826TemmieHighway Tolls (IOI18_highway)C++17
0 / 100
14 ms1232 KiB
#include "highway.h"
#include <bits/stdc++.h>

int n, m;
std::vector <std::vector <int>> g;

long long dist;

void find_pair(int _n, std::vector <int> _u, std::vector <int> _v, int a, int b) {
	n = _n;
	m = _u.size();
	g.resize(n);
	for (int i = 0; i < m; i++) {
		g[_u[i]].push_back(i);
		g[_v[i]].push_back(i);
	}
	dist = ask(std::vector <int> (m, 0)) / a;
	int root[2] = { -1, -1 };
	int sec = -1;
	{
		int l = 0, r = m - 1, best = m - 1;
		while (l <= r) {
			int mid = (l + r) >> 1;
			std::vector <int> cur(m, 1);
			for (int i = l; i <= mid; i++) {
				cur[i] = 0;
			}
			long long val = ask(cur);
			if (val == (dist - 1) * a + b) {
				best = mid;
				r = mid - 1;
			} else {
				l = mid + 1;
			}
		}
		root[0] = _u[best];
		root[1] = _v[best];
		sec = best;
	}
	assert(root[0] != -1 && root[1] != -1);
	assert(sec != -1);
	std::vector <int> nod[2];
	std::vector <int> par(n, -1);
	{
		std::queue <int> q;
		q.push(root[0]);
		q.push(root[1]);
		std::vector <bool> vis(n, false);
		std::vector <int> rof(n, -1);
		rof[root[0]] = root[0];
		rof[root[1]] = root[1];
		nod[0].push_back(root[0]);
		nod[1].push_back(root[1]);
		vis[root[0]] = vis[root[1]] = true;
		par[root[0]] = par[root[1]] = sec;
		while (q.size()) {
			int v = q.front(); q.pop();
			for (int x : g[v]) {
				int to = v ^ _u[x] ^ _v[x];
				if (vis[to]) {
					continue;
				}
				vis[to] = true;
				rof[to] = rof[v];
				nod[rof[v] == root[0] ? 0 : 1].push_back(to);
				q.push(to);
				par[to] = x;
			}
		}
	}
	int ans[2];
	for (int i = 0; i <= 1; i++) {
		int l = 0, r = (int) nod[i].size() - 1, best = nod[i][0];
		while (l < r) {
			int mid = (l + r) >> 1;
			std::vector <int> cur(m, 1);
			for (int x : nod[i ^ 1]) {
				cur[par[x]] = 0;
			}
			for (int j = 0; j <= mid; j++) {
				cur[par[nod[i][j]]] = 0;
			}
			long long val = ask(cur);
			if (val > dist * a) {
				best = nod[i][mid + 1];
				l = mid + 1;
			} else {
				r = mid;
			}
		}
		ans[i] = best;
	}
	answer(ans[0], ans[1]);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...