Submission #349078

# Submission time Handle Problem Language Result Execution time Memory
349078 2021-01-16T15:05:37 Z amunduzbaev Highway Tolls (IOI18_highway) C++14
51 / 100
365 ms 262148 KB
#include "highway.h"
#include <bits/stdc++.h>
#ifndef EVAL
#include "grader.cpp"
#endif
using namespace std;
 
#define pb push_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define vv vector 
typedef pair<int, int> pii; 
#define ll long long

const int NN = 90000;
vv<pii> edges[NN];
vv<int> tr;
vv<int> tt;
int un[NN], used[NN], wh[NN], rr, dd[NN], on[NN], l, r;
ll dis; 

void dfs(int u, int p, int d = 0){
	if(d == dis) tt.pb(u);
	
	dd[u] = d;
	for(auto x : edges[u]){
		if(x.ff == p) continue;
		on[x.ff] = x.ss;
		dfs(x.ff, u, d+1);
	}
}
 
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
	for(int i=0;i<sz(V);i++){
		edges[V[i]].pb({U[i], i});
		edges[U[i]].pb({V[i], i});
	}
	
	int mm = sz(V);
	tr.resize(mm, 0);
	dis = ask(tr)/A;
	
	
	queue<int> qq;
	qq.push(0);
	un[0] = 1, used[0] = 1;
	int last = 1;
	wh[last] = 0;
	
	// finding one of s or t
 
	while(!qq.empty()){
		int cur = qq.front(); qq.pop();
		for(auto x : edges[cur]){
			if(used[x.ff]) continue;
			un[x.ff] = ++last;
			used[x.ff] = 1;
			wh[last] = x.ff;
			qq.push(x.ff);
		}
	}
	
	//~ for(int i=0;i<N;i++) cout<<un[i]<<" ";
	//~ cout<<"\n";
 
	l = 1, r = last;
	ll br = dis * B;
	
	//~ cout<<un[0]<<" "<<un[66138]<<"\n";
	
	while(l < r){
		int m = (l + r -1)>>1;
		//~ cout<<l<e<" "<<m<<" "<<r<<"\n";
		
		for(int i=1;i<=m;i++){
			for(auto x:edges[wh[i]]){
				if(un[x.ff] > m) continue;
				tr[x.ss] = 1;
			}
		}
		
		
		ll res = ask(tr);
		tr.assign(mm, 0);
		
		//~ cout<<res<<" "<<br<<"\n";
		
		if(res < br) l = m+1;
		else r = m;
	}
	
	//~ int m = l;
	//~ for(int i=1;i<=m;i++){
		//~ for(auto x:edges[wh[i]]){
			//~ if(un[x.ff] > m) continue;
			//~ tr[x.ss] = 1;
		//~ }
	//~ }
	
	//~ int res = ask(tr);
	//~ tr.assign(mm, 0);
	
	//~ if(res < br) l = r;
	
	rr = wh[l];
	dfs(rr, -1, 0);
	
	l = 0, r = sz(tt)-1;
	
	while(l < r){
		int m = (l + r)>>1;
		tr.assign(mm, 0);
		for(int i=0;i<=m;i++) tr[on[tt[i]]] = 1;
		ll res = ask(tr);
		
		if(res > dis*A) r = m;
		else l = m+1;
	}
	
	//~ cout<<rr<<" "<<tt[l]<<"\n";
	answer(rr, tt[l]);
}
 
/*
 
7 6 1 2 0 4
0 1 
0 2 
0 3 
3 4 
2 6 
3 5 
 
*/
 
 
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2412 KB Output is correct
2 Correct 2 ms 2412 KB Output is correct
3 Correct 2 ms 2412 KB Output is correct
4 Correct 2 ms 2540 KB Output is correct
5 Correct 2 ms 2412 KB Output is correct
6 Correct 3 ms 2412 KB Output is correct
7 Correct 2 ms 2412 KB Output is correct
8 Correct 2 ms 2412 KB Output is correct
9 Correct 2 ms 2412 KB Output is correct
10 Correct 2 ms 2412 KB Output is correct
11 Correct 2 ms 2412 KB Output is correct
12 Correct 2 ms 2412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2668 KB Output is correct
2 Correct 16 ms 3180 KB Output is correct
3 Correct 267 ms 9596 KB Output is correct
4 Correct 305 ms 9484 KB Output is correct
5 Correct 302 ms 9600 KB Output is correct
6 Correct 310 ms 9488 KB Output is correct
7 Correct 227 ms 9544 KB Output is correct
8 Correct 218 ms 9404 KB Output is correct
9 Correct 183 ms 9632 KB Output is correct
10 Correct 320 ms 9476 KB Output is correct
11 Correct 262 ms 9888 KB Output is correct
12 Correct 286 ms 10920 KB Output is correct
13 Correct 220 ms 10216 KB Output is correct
14 Correct 327 ms 10604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 3692 KB Output is correct
2 Correct 35 ms 4588 KB Output is correct
3 Correct 38 ms 6196 KB Output is correct
4 Correct 167 ms 12168 KB Output is correct
5 Correct 133 ms 12276 KB Output is correct
6 Correct 123 ms 13608 KB Output is correct
7 Correct 170 ms 14068 KB Output is correct
8 Correct 162 ms 12460 KB Output is correct
9 Correct 119 ms 13100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2556 KB Output is correct
2 Correct 16 ms 3180 KB Output is correct
3 Correct 158 ms 8008 KB Output is correct
4 Correct 365 ms 9480 KB Output is correct
5 Correct 322 ms 9392 KB Output is correct
6 Correct 307 ms 9356 KB Output is correct
7 Correct 290 ms 9320 KB Output is correct
8 Correct 302 ms 9320 KB Output is correct
9 Correct 350 ms 9616 KB Output is correct
10 Correct 245 ms 9676 KB Output is correct
11 Correct 294 ms 10176 KB Output is correct
12 Correct 347 ms 10364 KB Output is correct
13 Correct 279 ms 10472 KB Output is correct
14 Correct 286 ms 10612 KB Output is correct
15 Correct 218 ms 9432 KB Output is correct
16 Correct 289 ms 9420 KB Output is correct
17 Correct 298 ms 10196 KB Output is correct
18 Correct 275 ms 10764 KB Output is correct
19 Correct 204 ms 9436 KB Output is correct
20 Correct 309 ms 11008 KB Output is correct
21 Correct 164 ms 10528 KB Output is correct
22 Correct 201 ms 10560 KB Output is correct
23 Correct 188 ms 10100 KB Output is correct
24 Correct 205 ms 10676 KB Output is correct
25 Correct 317 ms 14056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 306 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 292 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -