제출 #286118

#제출 시각아이디문제언어결과실행 시간메모리
286118mohammad통행료 (IOI18_highway)C++14
12 / 100
343 ms20724 KiB
#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
 
#define endl "\n"
// #define int long long

typedef long long ll ;
const ll ooo = 1e14 ;
const ll oo = 2e9 ;
const double PI = acos(-1) ;
const ll M = 1e9 + 7  ;
const int N = 10000010  ;

vector<ll> g[100010] , cost;
ll a , b , p[100010];
map<pair<int,int> , int>mp;

void dis(int i){
	cost[i] = 0 ;
	priority_queue<pair<ll,ll>> q;
	q.push({0 , i});
	while(q.size()){
		ll src = q.top().second  , c = -q.top().first;
		q.pop();
		if(cost[src] < c) continue ;
		// cout << src << endl;
		for(auto x : g[src]){
			// cout << x << ' ' << cost[x] << endl;
			if(cost[x] > c + a){
				p[x] = src;
				cost[x] = c + a;
				q.push({-cost[x] , x});
			}
		}
		// cout << endl;
	}
}

void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
	int M = U.size();
	a = A;b = B;
	for(int i = 0 ; i < M ; ++i) {
		g[V[i]].push_back(U[i]);
		g[U[i]].push_back(V[i]) , mp[{U[i] , V[i]}] = i , mp[{V[i] , U[i]}] = i;
	}
	cost = vector<ll>(N , ooo);
	dis(0);
	vector<int> w(M , 0);
	ll toll = ask(w);
	vector<int> ans;
	for(int i = 1 ; i < N; ++i) if(cost[i] == toll) ans.push_back(mp[{i , p[i]}]);
	while(ans.size() - 1){
		int sz = ans.size();
		for(int i = 0 ; i < sz / 2 ; ++i) w[ans[i]] = 1;
		ll tll = ask(w);
		for(int i = 0 ; i < sz / 2 ; ++i) w[ans[i]] = 0;
		if(toll == tll){
			vector<int> ans1 ;
			for(int i = sz / 2 ; i < sz ; ++i) 
				ans1.push_back(ans[i]) ;
			ans = ans1;
		}else{
			vector<int> ans1 ;
			for(int i = 0 ; i < sz / 2 ; ++i) 
				ans1.push_back(ans[i]) ;
			ans = ans1;
		}
	}
	int i = ans[0];
	ll y = (p[U[i]] == V[i] ? U[i] : V[i]);
	answer(0, y );
}
#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...