Submission #300535

#TimeUsernameProblemLanguageResultExecution timeMemory
300535ElyesChaabouniHighway Tolls (IOI18_highway)C++14
0 / 100
17 ms3328 KiB
#include "highway.h"
#include<bits/stdc++.h>

using namespace std;

vector<pair<int, int> >v[90005];
bool vu[90005];
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
	int M = U.size();
	vector<int>w(M);
	for(int i = 0; i < M; i++)
		w[i]=0;
	long long x=ask(w);
	int l=0, r=M-1;
	while(l != r)
	{
		int med=(l+r)/2;
		for(int i = 0; i <= med; i++)
			w[i]=1;
		long long cu = ask(w);
		if(cu!=x)
			r=med;
		else
			l=med+1;
		for(int i = 0; i <= med; i++)
			w[i]=0;
	}
	for(int i = 0; i < M; i++)
	{
		v[U[i]].push_back(make_pair(V[i], i));
		v[V[i]].push_back(make_pair(U[i], i));
	}
	vector<pair<int, int> >bfs;
	vu[U[l]]=1;
	for(int i = 0; i < v[U[l]].size(); i++)
	{
		bfs.push_back(v[U[l]][i]);
		vu[v[U[l]][i].first]=1;
	}
	for(int i = 0; i < bfs.size(); i++)
	{
		for(int j = 0; j < v[bfs[i].first].size(); j++)
		{
			if(!vu[v[bfs[i].first][j].first] && v[bfs[i].first][j].first != (bfs[i].first^U[bfs[i].second]^V[bfs[i].second]))
			{
				bfs.push_back(v[bfs[i].first][j]);
				vu[v[bfs[i].first][j].first]=1;
			}
		}
	}
	for(int i = 0; i < w.size(); i++)
		w[i]=0;
	for(int i = 0; i < M; i++)
	{
		if(vu[U[i]] && vu[V[i]])
			w[i]=1;
	}
	long long cu1=ask(w);
	int node1, node2;
	if(cu1==x)
	{
		node1=U[l];
	}
	else
	{
		int l1=0;
		int r1=bfs.size()-1;
		while(l != r)
		{
			int med=(l1+r1)/2;
			for(int i = 0; i <= med; i++)
				w[i]=0;
			long long cu11=ask(w);
			if(cu11==x)
				r1=med;
			else
				l1=med+1;
			for(int i = 0; i <= med; i++)
				w[i]=1;
		}
		node1=bfs[l1].first;
	}
	bfs.clear();
	for(int i = 0; i < 90005; i++)
		vu[i]=0;
	vu[V[l]]=1;
	for(int i = 0; i < v[V[l]].size(); i++)
	{
		bfs.push_back(v[V[l]][i]);
		vu[v[V[l]][i].first]=1;
	}
	for(int i = 0; i < bfs.size(); i++)
	{
		for(int j = 0; j < v[bfs[i].first].size(); j++)
		{
			if(!vu[v[bfs[i].first][j].first] && v[bfs[i].first][j].first != (bfs[i].first^U[bfs[i].second]^V[bfs[i].second]))
			{
				bfs.push_back(v[bfs[i].first][j]);
				vu[v[bfs[i].first][j].first]=1;
			}
		}
	}
	for(int i = 0; i < w.size(); i++)
		w[i]=0;
	for(int i = 0; i < M; i++)
	{
		if(vu[U[i]] && vu[V[i]])
			w[i]=1;
	}
	cu1=ask(w);
	if(cu1==x)
	{
		node2=V[l];
	}
	else
	{
		int l1=0;
		int r1=bfs.size()-1;
		while(l != r)
		{
			int med=(l1+r1)/2;
			for(int i = 0; i <= med; i++)
				w[i]=0;
			long long cu11=ask(w);
			if(cu11==x)
				r1=med;
			else
				l1=med+1;
			for(int i = 0; i <= med; i++)
				w[i]=1;
		}
		node2=bfs[l1].first;
	}
	answer(node1, node2);
}

Compilation message (stderr)

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:35:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for(int i = 0; i < v[U[l]].size(); i++)
      |                 ~~^~~~~~~~~~~~~~~~
highway.cpp:40:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |  for(int i = 0; i < bfs.size(); i++)
      |                 ~~^~~~~~~~~~~~
highway.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for(int j = 0; j < v[bfs[i].first].size(); j++)
      |                  ~~^~~~~~~~~~~~~~~~~~~~~~~~
highway.cpp:51:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for(int i = 0; i < w.size(); i++)
      |                 ~~^~~~~~~~~~
highway.cpp:87:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |  for(int i = 0; i < v[V[l]].size(); i++)
      |                 ~~^~~~~~~~~~~~~~~~
highway.cpp:92:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |  for(int i = 0; i < bfs.size(); i++)
      |                 ~~^~~~~~~~~~~~
highway.cpp:94:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |   for(int j = 0; j < v[bfs[i].first].size(); j++)
      |                  ~~^~~~~~~~~~~~~~~~~~~~~~~~
highway.cpp:103:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |  for(int i = 0; i < w.size(); i++)
      |                 ~~^~~~~~~~~~
#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...