제출 #139537

#제출 시각아이디문제언어결과실행 시간메모리
139537CaroLinda통행료 (IOI18_highway)C++14
12 / 100
201 ms10464 KiB
#include "highway.h"
#include <bits/stdc++.h>

#define debug printf
#define lp(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair

const int MAXN = 9e4+ 10 ;
const int MAXM = 13e4+10 ;

using namespace std ;

struct Edge
{

	int j , id ;

	Edge(int j = 0 , int id = 0) 
		: j(j) , id(id) {}

} ;

int n , m , S , T ;

int edgePai[MAXN] ;

vector<int> toAsk , possible ;

ll rad , Prev ;

vector<Edge> adj[MAXN] ;

bool marc[MAXN] ;

// --------------------------------


void prepareDfs()
{
	memset(marc,false, sizeof marc) ;
	possible.resize(0) ;
}

void dfs(int x , ll depth , ll curRad , bool allowed[])
{

	if( depth == curRad ) possible.pb(x) ;
	marc[x] = true ;

	for( Edge e : adj[x] )
		if( !marc[e.j] && allowed[e.id] )
		{
			edgePai[e.j] = e.id ;
			dfs( e.j , depth+1, curRad , allowed ) ;
		}

}


int findSpecial(int s , bool allowed[] , ll curRad ) 
{

	prepareDfs() ;	
	dfs(s , 0 , curRad , allowed) ;

	int l = 0 , r = possible.size() - 1 , mid , best=0 ;

	while( l <= r )
	{
		mid = (l+r)/2 ;

		lp(i,l,mid+1) toAsk[ edgePai[ possible[i] ] ] = 1 ;

		ll newTot = ask(toAsk) ;

		lp(i,l,mid+1) toAsk[ edgePai[ possible[i] ] ] = 0 ;

		if( newTot > Prev ) 
		{
			r = mid - 1 ;
			best = mid ;
		}

		else l = mid+1 ;

	}

	return possible[best] ;


}

bool allowed[MAXM] ;

void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
  
  m = U.size();
  n = N ;

  lp(i,0,m)
  {

  		
  	int a = U[i] , b = V[i] ;

  	adj[a].pb(Edge(b,i)) ;
  	adj[b].pb(Edge(a,i)) ;

  	toAsk.pb(0) ;
  	allowed[i] = 1 ;

  }

  Prev = ask(toAsk) ;
  rad = Prev/A ;
  

  T = findSpecial(0 , allowed , rad) ;

  answer(S,T) ;

}
 
#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...