Submission #1058139

# Submission time Handle Problem Language Result Execution time Memory
1058139 2024-08-14T08:40:19 Z ReLice Highway Tolls (IOI18_highway) C++17
90 / 100
140 ms 28596 KB
#include "highway.h"
#include <bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define pb push_back
#define pf push_front
#define sz size()
#define bc back()
#define pob pop_back()
#define pof pop_front()
#define fr first
#define sc second
using namespace std;
const ll N=2e5+7;
const ll inf=1e18;
vector<vector<array<ll,2>>> g(N), g2(N);
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
	ll M = V.sz;
	ll s, t, rt;
	ll n = N;
	vll v, u;
	ll i;
	
	for(auto i : V) v.pb(i);
	for(auto i : U) u.pb(i);
	
	vector<int> w(M, 0);
	
	ll x = ask(w);
	
	for(i=0;i<M;i++){
		g[v[i]].pb({u[i], i});
		g[u[i]].pb({v[i], i});
	}
	
	{//getting vertex on the path
		ll l = 0, r = n;
		while(l + 1 < r){
			ll m = (l + r) / 2;
			
			if(r - l > 60000) m = 60000;
			
			w.assign(M, 0);
			
			for(i=0;i<m;i++){
				for(auto [to, r] : g[i]) w[r] = 1;
			}
			
			ll y = ask(w);
			
			if(y == x) l = m;
			else r = m;
		}
		
		rt = r - 1;
	}
	
	vll p(n), d(n);
	vll pr(n), tour;
	vector<vll> dd(n);
	
	auto bfs = [&](ll s){
		for(i=0;i<n;i++){
			dd[i].clear();
			d[i] = inf;
			pr[i] = p[i] = -1;
		}
		
		queue<ll> q;
		q.push(s);
		d[s] = 0;
		
		while(q.size()){
			ll x = q.front();
			q.pop();
			
			dd[d[x]].pb(x);
			
			for(auto [to, r] : g[x]){
				if(d[to] > d[x] + 1){
					d[to] = d[x] + 1 ;
					pr[to] = r;
					p[to] = x;
					q.push(to);
				}
			}
		}
		
		tour.clear();
		for(i=0;i<n;i++){
			for(auto j : dd[i]) tour.pb(j);
		}
	};
	
	vll path;
	auto calc = [&](ll N){
		ll l = 0, r = N;
		while(l + 1 < r){
			ll m = (l + r) / 2;
			
			if(n == N && r - l > 60000) m = 30000;
			
			w.assign(M, 1);
			
			for(auto i : path) w[i] =0;
			
			//~ cout<<m<<endl;
			for(i=1;i<m;i++) {
				w[pr[tour[i]]] = 0;
				//~ cout<<v[pr[tour[i]]]<<' '<<u[pr[tour[i]]]<<endl;
			}
			
			ll y = ask(w);
				
			if(x == y) r = m;
			else l = m;
		}
		
		return r - 1;
	};
	
	bfs(rt);
	
	ll k = calc(n);
	s = tour[k];
	
	{
		ll x = s;
		while(x != rt){
			path.pb(pr[x]);
			x = p[x];
		}
	}
	
	t = tour[calc(k)];
	
	answer(s, t);
}


# Verdict Execution time Memory Grader output
1 Correct 3 ms 9816 KB Output is correct
2 Correct 3 ms 9816 KB Output is correct
3 Correct 3 ms 9816 KB Output is correct
4 Correct 3 ms 9816 KB Output is correct
5 Correct 4 ms 9848 KB Output is correct
6 Correct 3 ms 9816 KB Output is correct
7 Correct 3 ms 9816 KB Output is correct
8 Correct 3 ms 9816 KB Output is correct
9 Correct 4 ms 9816 KB Output is correct
10 Correct 3 ms 9816 KB Output is correct
11 Correct 3 ms 9816 KB Output is correct
12 Correct 3 ms 9816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 10 ms 11352 KB Output is correct
3 Correct 106 ms 24236 KB Output is correct
4 Correct 120 ms 24052 KB Output is correct
5 Correct 98 ms 24024 KB Output is correct
6 Correct 94 ms 24012 KB Output is correct
7 Correct 85 ms 24188 KB Output is correct
8 Correct 88 ms 24236 KB Output is correct
9 Correct 84 ms 24036 KB Output is correct
10 Correct 93 ms 24212 KB Output is correct
11 Correct 108 ms 24288 KB Output is correct
12 Correct 110 ms 24504 KB Output is correct
13 Correct 86 ms 24600 KB Output is correct
14 Correct 89 ms 24292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 11608 KB Output is correct
2 Correct 16 ms 13260 KB Output is correct
3 Correct 22 ms 14900 KB Output is correct
4 Correct 66 ms 24504 KB Output is correct
5 Correct 64 ms 24752 KB Output is correct
6 Correct 70 ms 25384 KB Output is correct
7 Correct 69 ms 25576 KB Output is correct
8 Correct 71 ms 24832 KB Output is correct
9 Correct 64 ms 24852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9816 KB Output is correct
2 Correct 12 ms 11496 KB Output is correct
3 Correct 58 ms 21252 KB Output is correct
4 Correct 87 ms 24136 KB Output is correct
5 Correct 75 ms 24096 KB Output is correct
6 Correct 76 ms 24252 KB Output is correct
7 Correct 72 ms 24068 KB Output is correct
8 Correct 83 ms 24128 KB Output is correct
9 Correct 92 ms 24144 KB Output is correct
10 Correct 79 ms 24264 KB Output is correct
11 Correct 92 ms 24556 KB Output is correct
12 Correct 99 ms 24404 KB Output is correct
13 Correct 98 ms 24296 KB Output is correct
14 Correct 87 ms 24360 KB Output is correct
15 Correct 81 ms 24196 KB Output is correct
16 Correct 75 ms 24152 KB Output is correct
17 Correct 95 ms 24500 KB Output is correct
18 Correct 88 ms 24516 KB Output is correct
19 Correct 88 ms 24080 KB Output is correct
20 Correct 94 ms 24544 KB Output is correct
21 Correct 75 ms 25352 KB Output is correct
22 Correct 77 ms 24668 KB Output is correct
23 Correct 82 ms 24596 KB Output is correct
24 Correct 89 ms 24644 KB Output is correct
25 Correct 102 ms 26144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 11608 KB Output is correct
2 Correct 11 ms 11656 KB Output is correct
3 Correct 99 ms 25408 KB Output is correct
4 Correct 94 ms 26332 KB Output is correct
5 Correct 122 ms 28244 KB Output is correct
6 Correct 118 ms 28144 KB Output is correct
7 Correct 127 ms 28148 KB Output is correct
8 Correct 109 ms 28208 KB Output is correct
9 Correct 125 ms 22548 KB Output is correct
10 Correct 99 ms 22816 KB Output is correct
11 Correct 118 ms 24244 KB Output is correct
12 Correct 116 ms 26780 KB Output is correct
13 Correct 137 ms 27468 KB Output is correct
14 Correct 114 ms 28124 KB Output is correct
15 Correct 119 ms 28096 KB Output is correct
16 Correct 113 ms 24276 KB Output is correct
17 Correct 96 ms 24504 KB Output is correct
18 Correct 92 ms 24628 KB Output is correct
19 Correct 99 ms 24392 KB Output is correct
20 Correct 84 ms 24544 KB Output is correct
21 Correct 119 ms 27896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 11352 KB Output is correct
2 Correct 11 ms 11692 KB Output is correct
3 Correct 89 ms 25140 KB Output is correct
4 Correct 101 ms 26072 KB Output is correct
5 Partially correct 119 ms 26616 KB Output is partially correct
6 Correct 108 ms 28052 KB Output is correct
7 Correct 93 ms 25184 KB Output is correct
8 Correct 115 ms 26324 KB Output is correct
9 Correct 100 ms 26340 KB Output is correct
10 Correct 117 ms 28176 KB Output is correct
11 Correct 121 ms 28148 KB Output is correct
12 Correct 127 ms 28152 KB Output is correct
13 Correct 123 ms 24264 KB Output is correct
14 Correct 93 ms 22884 KB Output is correct
15 Correct 82 ms 24260 KB Output is correct
16 Correct 101 ms 22820 KB Output is correct
17 Correct 100 ms 24200 KB Output is correct
18 Correct 109 ms 22696 KB Output is correct
19 Correct 129 ms 27052 KB Output is correct
20 Correct 107 ms 27524 KB Output is correct
21 Correct 132 ms 28088 KB Output is correct
22 Correct 132 ms 28596 KB Output is correct
23 Correct 117 ms 28176 KB Output is correct
24 Correct 107 ms 28264 KB Output is correct
25 Correct 125 ms 28120 KB Output is correct
26 Correct 112 ms 28128 KB Output is correct
27 Correct 81 ms 24932 KB Output is correct
28 Partially correct 80 ms 24460 KB Output is partially correct
29 Partially correct 87 ms 24868 KB Output is partially correct
30 Correct 87 ms 25040 KB Output is correct
31 Partially correct 107 ms 24368 KB Output is partially correct
32 Correct 106 ms 24280 KB Output is correct
33 Correct 95 ms 25068 KB Output is correct
34 Correct 83 ms 24736 KB Output is correct
35 Correct 76 ms 24636 KB Output is correct
36 Correct 87 ms 24220 KB Output is correct
37 Correct 86 ms 24944 KB Output is correct
38 Partially correct 99 ms 24636 KB Output is partially correct
39 Correct 140 ms 28044 KB Output is correct
40 Correct 122 ms 27932 KB Output is correct
41 Partially correct 129 ms 27916 KB Output is partially correct
42 Correct 121 ms 27888 KB Output is correct