Submission #797402

# Submission time Handle Problem Language Result Execution time Memory
797402 2023-07-29T10:26:23 Z Sohsoh84 Highway Tolls (IOI18_highway) C++17
90 / 100
212 ms 42020 KB
#include "highway.h"
#include <bits/stdc++.h>

using namespace std;

#define sep		' '
#define debug(x)	cerr << #x << ": " << x << endl;
#define all(x)		(x).begin(), (x).end()

const int MAXN = 1e6 + 10;

int askcnt = 0;
int from[MAXN], to[MAXN], n, m, par[MAXN], mn;
vector<int> adj[MAXN], dfs_order, fuck;

inline int f(int ind, int v) {
	return from[ind] ^ to[ind] ^ v;
}

void dfs(int v, int p) {
	dfs_order.push_back(v);
	for (int ind : adj[v]) {
		int u = f(ind, v);
		if (u == p) continue;

		par[u] = ind;
		dfs(u, v);
	}
}


inline vector<int> seg(int l, int r) {
	vector<int> ans;
	for (int i = l; i <= r; i++)
		ans.push_back(par[dfs_order[i]]);

	return ans;
}

inline int get(vector<int> vec) {
	askcnt++;
	assert(askcnt <= 90);
	vector<int> W(m);
	for (int i = 0; i < m; i++) W[i] = 1;
	for (int e : fuck)
		W[e] = 0;

	for (int e : vec)
		W[e] = 1;

	return ask(W);
}

inline int getp(vector<int> vec) {
	askcnt++;
	assert(askcnt <= 90);
	vector<int> W(m);
	for (int i = 0; i < m; i++) 
		W[i] = 1;
	for (int e : vec)
		W[e] = 0;

	return ask(W);
}

inline int get(int l, int r) {
	return get(seg(l, r));
}

inline int getp(int l, int r) {
	return getp(seg(l, r));
}

inline int find(int root) {
	par[root] = -1;
	dfs_order.clear();

	dfs(root, root);
	int l = 1, r = int(dfs_order.size()) - 1;

	while (l < r) {
		int mid = (l + r) >> 1;	
		if (getp(1, mid) == mn) r = mid;
		else l = mid + 1;
	}

	return dfs_order[l];

}

int dist[MAXN];

inline vector<int> random_spt() {
	vector<int> ans;
	queue<int> q;

	int l = 0, r = n - 1;
	while (l < r) {
		int mid = (l + r) >> 1;
		vector<int> W(m);
	
		for (int i = 0; i < m; i++)
			if (from[i] <= mid || to[i] <= mid)
				W[i] = 1;

		if (ask(W) == mn) l = mid + 1;
		else r = mid;
	}

	int v = l;
	memset(dist, 63, sizeof dist);
	q.push(v);
	dist[v] = 0;

	while (!q.empty()) {
		int v = q.front();
		q.pop();

		for (int ind : adj[v]) {
			int u = f(ind, v);
			if (dist[u] > dist[v] + 1) {
				dist[u] = dist[v] + 1;
				q.push(u);
				ans.push_back(ind);
			}
		}
	}

	return ans;
}

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

	for (int i = 0; i < m; i++) {
		from[i] = U[i];
		to[i] = V[i];

		adj[from[i]].push_back(i);
		adj[to[i]].push_back(i);
	}

	for (int i = 0; i < m; i++)
		fuck.push_back(i);

	mn = get({});
	vector<int> tmp = random_spt();

	fuck = tmp;
	for (int i = 0; i < n; i++) adj[i].clear();
	for (int ind : tmp) {
		adj[from[ind]].push_back(ind);
		adj[to[ind]].push_back(ind);
	}


	int v = find(0);
	int u = find(v);
	
	cerr << u << sep << v << endl;

	answer(u, v);
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 27732 KB Output is correct
2 Correct 17 ms 27676 KB Output is correct
3 Correct 15 ms 27728 KB Output is correct
4 Correct 17 ms 27608 KB Output is correct
5 Correct 15 ms 27668 KB Output is correct
6 Correct 14 ms 27672 KB Output is correct
7 Correct 19 ms 27660 KB Output is correct
8 Correct 13 ms 27672 KB Output is correct
9 Correct 12 ms 27728 KB Output is correct
10 Correct 13 ms 27728 KB Output is correct
11 Correct 14 ms 27672 KB Output is correct
12 Correct 14 ms 27736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 27740 KB Output is correct
2 Correct 23 ms 28444 KB Output is correct
3 Correct 155 ms 35076 KB Output is correct
4 Correct 131 ms 34988 KB Output is correct
5 Correct 128 ms 35016 KB Output is correct
6 Correct 162 ms 35072 KB Output is correct
7 Correct 150 ms 35112 KB Output is correct
8 Correct 135 ms 35020 KB Output is correct
9 Correct 144 ms 35084 KB Output is correct
10 Correct 118 ms 35076 KB Output is correct
11 Correct 143 ms 36588 KB Output is correct
12 Correct 132 ms 37624 KB Output is correct
13 Correct 130 ms 36696 KB Output is correct
14 Correct 159 ms 36764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 29332 KB Output is correct
2 Correct 40 ms 30968 KB Output is correct
3 Correct 39 ms 32552 KB Output is correct
4 Correct 82 ms 41972 KB Output is correct
5 Correct 86 ms 41876 KB Output is correct
6 Correct 90 ms 41964 KB Output is correct
7 Correct 104 ms 42000 KB Output is correct
8 Correct 103 ms 41972 KB Output is correct
9 Correct 84 ms 42020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 27728 KB Output is correct
2 Correct 24 ms 28484 KB Output is correct
3 Correct 95 ms 33428 KB Output is correct
4 Correct 128 ms 35008 KB Output is correct
5 Correct 132 ms 34976 KB Output is correct
6 Correct 112 ms 35040 KB Output is correct
7 Correct 149 ms 35044 KB Output is correct
8 Correct 135 ms 35008 KB Output is correct
9 Correct 134 ms 35060 KB Output is correct
10 Correct 143 ms 35056 KB Output is correct
11 Correct 129 ms 36124 KB Output is correct
12 Correct 147 ms 37484 KB Output is correct
13 Correct 173 ms 36900 KB Output is correct
14 Correct 121 ms 37348 KB Output is correct
15 Correct 111 ms 35068 KB Output is correct
16 Correct 110 ms 34960 KB Output is correct
17 Correct 137 ms 37080 KB Output is correct
18 Correct 128 ms 37176 KB Output is correct
19 Correct 110 ms 35024 KB Output is correct
20 Correct 141 ms 37988 KB Output is correct
21 Correct 111 ms 35292 KB Output is correct
22 Correct 113 ms 35328 KB Output is correct
23 Correct 96 ms 35412 KB Output is correct
24 Correct 118 ms 36076 KB Output is correct
25 Correct 154 ms 41252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 28468 KB Output is correct
2 Correct 25 ms 28624 KB Output is correct
3 Correct 125 ms 35408 KB Output is correct
4 Correct 174 ms 35756 KB Output is correct
5 Correct 196 ms 36468 KB Output is correct
6 Correct 168 ms 36792 KB Output is correct
7 Correct 160 ms 36428 KB Output is correct
8 Correct 186 ms 36852 KB Output is correct
9 Correct 159 ms 33912 KB Output is correct
10 Correct 135 ms 34420 KB Output is correct
11 Correct 181 ms 34796 KB Output is correct
12 Correct 183 ms 35908 KB Output is correct
13 Correct 167 ms 36216 KB Output is correct
14 Correct 212 ms 36696 KB Output is correct
15 Correct 182 ms 36380 KB Output is correct
16 Correct 148 ms 35072 KB Output is correct
17 Correct 133 ms 35392 KB Output is correct
18 Correct 131 ms 35444 KB Output is correct
19 Correct 126 ms 35428 KB Output is correct
20 Correct 136 ms 35516 KB Output is correct
21 Correct 161 ms 36792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 28484 KB Output is correct
2 Correct 29 ms 28636 KB Output is correct
3 Correct 157 ms 35384 KB Output is correct
4 Correct 141 ms 35560 KB Output is correct
5 Partially correct 156 ms 35752 KB Output is partially correct
6 Correct 207 ms 36852 KB Output is correct
7 Correct 145 ms 35452 KB Output is correct
8 Partially correct 156 ms 35612 KB Output is partially correct
9 Partially correct 144 ms 35728 KB Output is partially correct
10 Correct 171 ms 36816 KB Output is correct
11 Partially correct 168 ms 36492 KB Output is partially correct
12 Correct 162 ms 36476 KB Output is correct
13 Correct 128 ms 34540 KB Output is correct
14 Correct 122 ms 34312 KB Output is correct
15 Correct 176 ms 34548 KB Output is correct
16 Correct 181 ms 34464 KB Output is correct
17 Correct 132 ms 34540 KB Output is correct
18 Correct 127 ms 34456 KB Output is correct
19 Correct 186 ms 36176 KB Output is correct
20 Partially correct 176 ms 36060 KB Output is partially correct
21 Correct 183 ms 36664 KB Output is correct
22 Correct 207 ms 36320 KB Output is correct
23 Partially correct 160 ms 36636 KB Output is partially correct
24 Partially correct 159 ms 36632 KB Output is partially correct
25 Partially correct 178 ms 36356 KB Output is partially correct
26 Correct 182 ms 36280 KB Output is correct
27 Partially correct 122 ms 35492 KB Output is partially correct
28 Correct 118 ms 35404 KB Output is correct
29 Partially correct 143 ms 35620 KB Output is partially correct
30 Partially correct 148 ms 35460 KB Output is partially correct
31 Correct 145 ms 35456 KB Output is correct
32 Partially correct 129 ms 35344 KB Output is partially correct
33 Partially correct 126 ms 35576 KB Output is partially correct
34 Correct 128 ms 35444 KB Output is correct
35 Correct 152 ms 35380 KB Output is correct
36 Correct 126 ms 35352 KB Output is correct
37 Correct 153 ms 35516 KB Output is correct
38 Partially correct 128 ms 35912 KB Output is partially correct
39 Partially correct 156 ms 37216 KB Output is partially correct
40 Correct 179 ms 37332 KB Output is correct
41 Correct 211 ms 36752 KB Output is correct
42 Correct 167 ms 36708 KB Output is correct