Submission #136477

# Submission time Handle Problem Language Result Execution time Memory
136477 2019-07-25T10:58:49 Z amiratou Highway Tolls (IOI18_highway) C++14
0 / 100
377 ms 262148 KB
#include "highway.h"
#include <bits/stdc++.h>
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
vector<vector<ii> > vec;
vector<int> query;
vector<ii> target;
ll dist,a,b;
void dfs(int node,int high,int p){
	if(high!=-1)target.pb(ii(high,node));
	for(auto child:vec[node])
		if(child.fi!=p)
			dfs(child.fi,child.se,node);
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
	int M = U.size();
	a=A,b=B;
	vec.resize(N);
	query.resize(M);
	for (int i = 0; i < M; ++i)
	{
		vec[U[i]].pb(ii(V[i],i));
		vec[V[i]].pb(ii(U[i],i));
	}
	int start=0;
	for (int i = 0; i < N; ++i)
	{
		if(vec[i].size()==1){
			start=i;
			break;
		}
	}
	fill(query.begin(),query.end(),0);
	dist=ask(query);
	dfs(start,-1,0);
	//sort(target.begin(),target.end());
	int l=0,r=(int)(target.size())-1;
	int n1,n2;
	while(l<=r){
		int med=(l+r)>>1;
		fill(query.begin(),query.end(),0);
		for (int i = l; i <= med; ++i)
			query[target[i].fi]=1;
		ll check=ask(query);
		if(check==dist)
			l=med+1;
		else if(check==(dist/A)*B){
			r=med;
		}
		else{
			ll nb_edges=(check-dist)/(B-A);
			//cerr<<l<<" "<<r<<" "<<nb_edges<<"\n";
			n1=(((med-nb_edges)<0)?start:target[med-nb_edges].se);
			n2=target[r].se;
			//cerr<<n1<<" "<<n2<<"\n";
			break;
		}
	}
	answer(n1, n2);
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:63:8: warning: 'n2' may be used uninitialized in this function [-Wmaybe-uninitialized]
  answer(n1, n2);
  ~~~~~~^~~~~~~~
highway.cpp:63:8: warning: 'n1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 248 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 1848 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 396 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 377 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 370 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -