Submission #175786

# Submission time Handle Problem Language Result Execution time Memory
175786 2020-01-07T11:01:48 Z oolimry Highway Tolls (IOI18_highway) C++14
100 / 100
327 ms 11056 KB
#include "highway.h"
#include <bits/stdc++.h> 
using namespace std;

typedef pair<int,int> ii;
ii vis[90005];
vector<ii> adj[90005];
void find_pair(int n, vector<int> U, vector<int> V, int A, int B) {
	int m = U.size();
	vector<int> w; w.assign(m, 0);

	for(int i = 0;i < m;i++){
		adj[U[i]].push_back(ii(V[i],i));
		adj[V[i]].push_back(ii(U[i],i));
	}

	long long allLight = ask(w);
	int low = 0, high = m - 1;
	while(low < high){
		int s = (high + low) / 2;
		for(int i = 0;i < m;i++) w[i] = (i <= s);
		if(ask(w) == allLight) low = s + 1;
		else high = s; 
	}
	
	int sRoot = U[low], tRoot = V[low];
	vis[sRoot] = ii(1,0); vis[tRoot] = ii(2,0);
	queue<int> bfs; bfs.push(sRoot); bfs.push(tRoot);
	vector<int> sEdges, tEdges;
	int mid = low;
	
	while(!bfs.empty()){
		int u = bfs.front(); bfs.pop();
		for(ii v : adj[u]){
			if(vis[v.first] == ii(0,0)){
				bfs.push(v.first);
				vis[v.first] = ii(vis[u].first, vis[u].second + 1);
				if(vis[u].first == 1) sEdges.push_back(v.second);
				else tEdges.push_back(v.second);
			}
		}
	}
	
	int S = -1, T = -1;
	w.assign(m, 1); w[mid] = 0;
	for(int e : tEdges) w[e] = 0;
	low = -2, high = sEdges.size();
	while(true){
		if(low == high - 1) break;
		int s = (high + low) / 2;
		for(int i = 0;i < (int) sEdges.size();i++) w[sEdges[i]] = !(i <= s);
		if(ask(w) != allLight) low = s;
		else high = s;
	}
	
	if(high == -1) S = sRoot;
	else{
		int u = U[sEdges[high]], v = V[sEdges[high]];
		if(vis[u].second > vis[v].second) S = u;
		else S = v;
	}
	
	w.assign(m, 1); w[mid] = 0;
	for(int e : sEdges) w[e] = 0;
	low = -2, high = tEdges.size();
	while(true){
		if(low == high - 1) break;
		int s = (high + low) / 2;
		for(int i = 0;i < (int) tEdges.size();i++) w[tEdges[i]] = !(i <= s);
		if(ask(w) != allLight) low = s;
		else high = s;
	}
	
	if(high == -1) T = tRoot;
	else{
		int u = U[tEdges[high]], v = V[tEdges[high]];
		if(vis[u].second > vis[v].second) T = u;
		else T = v;
	}
	answer(S, T);
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2424 KB Output is correct
2 Correct 4 ms 2424 KB Output is correct
3 Correct 4 ms 2424 KB Output is correct
4 Correct 4 ms 2424 KB Output is correct
5 Correct 4 ms 2424 KB Output is correct
6 Correct 4 ms 2424 KB Output is correct
7 Correct 4 ms 2448 KB Output is correct
8 Correct 4 ms 2424 KB Output is correct
9 Correct 4 ms 2424 KB Output is correct
10 Correct 4 ms 2424 KB Output is correct
11 Correct 4 ms 2424 KB Output is correct
12 Correct 4 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2500 KB Output is correct
2 Correct 22 ms 3152 KB Output is correct
3 Correct 205 ms 9064 KB Output is correct
4 Correct 212 ms 8860 KB Output is correct
5 Correct 229 ms 8944 KB Output is correct
6 Correct 195 ms 8912 KB Output is correct
7 Correct 218 ms 8996 KB Output is correct
8 Correct 191 ms 8852 KB Output is correct
9 Correct 176 ms 8908 KB Output is correct
10 Correct 211 ms 9016 KB Output is correct
11 Correct 206 ms 8252 KB Output is correct
12 Correct 201 ms 8432 KB Output is correct
13 Correct 189 ms 8420 KB Output is correct
14 Correct 226 ms 8352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3248 KB Output is correct
2 Correct 40 ms 3752 KB Output is correct
3 Correct 57 ms 4512 KB Output is correct
4 Correct 166 ms 8320 KB Output is correct
5 Correct 165 ms 8424 KB Output is correct
6 Correct 154 ms 8380 KB Output is correct
7 Correct 162 ms 8232 KB Output is correct
8 Correct 175 ms 8224 KB Output is correct
9 Correct 155 ms 8400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2428 KB Output is correct
2 Correct 26 ms 3068 KB Output is correct
3 Correct 144 ms 7640 KB Output is correct
4 Correct 186 ms 8948 KB Output is correct
5 Correct 182 ms 8912 KB Output is correct
6 Correct 206 ms 9012 KB Output is correct
7 Correct 196 ms 9028 KB Output is correct
8 Correct 200 ms 8924 KB Output is correct
9 Correct 222 ms 8908 KB Output is correct
10 Correct 209 ms 8932 KB Output is correct
11 Correct 212 ms 8308 KB Output is correct
12 Correct 211 ms 8456 KB Output is correct
13 Correct 240 ms 8448 KB Output is correct
14 Correct 188 ms 8308 KB Output is correct
15 Correct 193 ms 8912 KB Output is correct
16 Correct 193 ms 8948 KB Output is correct
17 Correct 196 ms 8380 KB Output is correct
18 Correct 206 ms 8400 KB Output is correct
19 Correct 196 ms 8904 KB Output is correct
20 Correct 220 ms 8388 KB Output is correct
21 Correct 188 ms 9328 KB Output is correct
22 Correct 186 ms 9340 KB Output is correct
23 Correct 184 ms 9200 KB Output is correct
24 Correct 195 ms 9284 KB Output is correct
25 Correct 228 ms 8612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 3136 KB Output is correct
2 Correct 31 ms 3192 KB Output is correct
3 Correct 246 ms 9264 KB Output is correct
4 Correct 254 ms 9964 KB Output is correct
5 Correct 300 ms 10692 KB Output is correct
6 Correct 327 ms 10676 KB Output is correct
7 Correct 278 ms 10656 KB Output is correct
8 Correct 290 ms 10656 KB Output is correct
9 Correct 246 ms 8376 KB Output is correct
10 Correct 252 ms 8992 KB Output is correct
11 Correct 255 ms 9176 KB Output is correct
12 Correct 267 ms 10384 KB Output is correct
13 Correct 278 ms 10480 KB Output is correct
14 Correct 319 ms 10664 KB Output is correct
15 Correct 279 ms 10712 KB Output is correct
16 Correct 303 ms 9544 KB Output is correct
17 Correct 191 ms 9228 KB Output is correct
18 Correct 168 ms 9428 KB Output is correct
19 Correct 172 ms 9300 KB Output is correct
20 Correct 195 ms 9420 KB Output is correct
21 Correct 300 ms 11056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 3208 KB Output is correct
2 Correct 29 ms 3180 KB Output is correct
3 Correct 242 ms 9324 KB Output is correct
4 Correct 239 ms 9572 KB Output is correct
5 Correct 259 ms 9688 KB Output is correct
6 Correct 309 ms 10660 KB Output is correct
7 Correct 224 ms 9300 KB Output is correct
8 Correct 231 ms 9404 KB Output is correct
9 Correct 248 ms 9648 KB Output is correct
10 Correct 311 ms 10748 KB Output is correct
11 Correct 302 ms 10600 KB Output is correct
12 Correct 302 ms 10656 KB Output is correct
13 Correct 252 ms 9260 KB Output is correct
14 Correct 240 ms 8840 KB Output is correct
15 Correct 255 ms 9176 KB Output is correct
16 Correct 258 ms 8828 KB Output is correct
17 Correct 264 ms 9188 KB Output is correct
18 Correct 250 ms 8904 KB Output is correct
19 Correct 284 ms 10256 KB Output is correct
20 Correct 317 ms 10728 KB Output is correct
21 Correct 273 ms 10636 KB Output is correct
22 Correct 313 ms 10660 KB Output is correct
23 Correct 306 ms 10672 KB Output is correct
24 Correct 310 ms 10728 KB Output is correct
25 Correct 305 ms 10760 KB Output is correct
26 Correct 306 ms 10808 KB Output is correct
27 Correct 244 ms 9352 KB Output is correct
28 Correct 220 ms 9336 KB Output is correct
29 Correct 182 ms 9616 KB Output is correct
30 Correct 189 ms 9512 KB Output is correct
31 Correct 202 ms 9428 KB Output is correct
32 Correct 198 ms 9348 KB Output is correct
33 Correct 205 ms 9632 KB Output is correct
34 Correct 191 ms 9372 KB Output is correct
35 Correct 191 ms 9420 KB Output is correct
36 Correct 221 ms 9316 KB Output is correct
37 Correct 190 ms 9604 KB Output is correct
38 Correct 202 ms 9376 KB Output is correct
39 Correct 301 ms 10856 KB Output is correct
40 Correct 298 ms 10820 KB Output is correct
41 Correct 298 ms 10724 KB Output is correct
42 Correct 322 ms 10856 KB Output is correct