Submission #1068182

#TimeUsernameProblemLanguageResultExecution timeMemory
1068182Faisal_SaqibHighway Tolls (IOI18_highway)C++17
5 / 100
77 ms8912 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
long long ask(const std::vector<int> &w);
void answer(int s, int t);
const ll NP=1e5;
vector<pair<ll,ll>> ma[NP],tmp;
vector<int> w;
ll mi,a,b,calls=0;
int dfs(int x,int p=-1)
{
	tmp.clear();
	for(auto i:ma[x])
	{
		if(i.second!=p)
		{
			tmp.pb(i);
		}
	}
	int s=-1;
	int e=(int)tmp.size();
	while(s+1<e)
	{
		int mid=(s+e)/2;
		for(int j=s+1;j<=mid;j++)
			w[tmp[j].first]=1;
		calls++;
		if(calls > 60)
			answer(-1,-1);
		ll cost=ask(w);
		for(int j=s+1;j<=mid;j++)
			w[tmp[j].first]=0;
		if((cost>mi)) // edge is inside
		{
			e=mid;
		}
		else{
			s=mid;
		}
	}
	if(e==(tmp.size()))
	{
		// no edge
		return x;
	}
	else
	{
		return dfs(tmp[e].second,x);
	}
}
void find_pair(int n, std::vector<int> u, std::vector<int> v, int A, int B)
{
	int m=u.size();
	w.resize(m,0);
	a=A;
	b=B;
	calls=0;
	calls++;
	if(calls > 60)
		answer(-1,-1);
	mi=ask(w);
	for(int i=0;i<n;i++)
	{
		ma[i].clear();
	}
	for(int i=0;i<m;i++)
	{
		ma[u[i]].pb({i,v[i]});
		ma[v[i]].pb({i,u[i]});
	}
	answer(0,dfs(0));
}

Compilation message (stderr)

highway.cpp: In function 'int dfs(int, int)':
highway.cpp:42:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  if(e==(tmp.size()))
      |     ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...