답안 #132723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132723 2019-07-19T11:52:16 Z dvdg6566 통행료 (IOI18_highway) C++14
0 / 100
445 ms 262148 KB
#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
#define mp make_pair
#define pb emplace_back
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound

vpi V[100100];
int sub[100100];
vi q;
int par[100100];
int rt;
int blk[100100];
int ban[100100];
int ind;

int dfs(int x, int p){
	ban[x]=0;
	if (blk[x])return 0;
	par[x]=p;
	sub[x] = 1;
	for (auto i : V[x]){
		if (i.f==par[x])continue;
		sub[x] += dfs(i.f,x);
	}
	return sub[x];
}

void dfs2(int x, int p){
	// cout<<"DFS2 "<<x<<' '<<p<<'\n';
	for (auto i : V[x]){
		q[i.s] =1;
		if (i.f==par[x])continue;
		dfs2(i.f,x);
	}
}

void find_pair(int N, std::vector<int> U, std::vector<int> _V, int A, int B) {
  int M = U.size();
  q.resize(N-1,0);
  for (int i=0;i<M;++i){
  	int a=_V[i];
  	int b=U[i];
  	V[a].pb(b,i);
  	V[b].pb(a,i);
  }
  dfs(0,-1);
  int pos = N;
  // for (auto i : q)cout<<i<<' ';cout<<'\n';
  int len = ask(q);
  // cout<<len<<'\n';
  while (pos > 1){
  	// cout<<"Position "<<pos<<'\n';
  	ban[rt]=1;
  	int mindst = 1e9;
  	ind = 0;
  	for (int i=1;i<N;++i)if(!ban[i]){
  		if (abs(sub[rt] - 2*sub[i]) < mindst){
  			mindst = abs(sub[0] - 2*sub[i]);
  			ind = i;
  		}
  	}
  	for (int i=0;i<N;++i)q[i]=0;
  	// cout<<ind<<'\n';
  	dfs2(ind,par[ind]);
  	// for (auto i : q)cout<<i<<' ';cout<<'\n';
  	int t = ask(q);
  	if (t != len){
  		// cout<<"Reroot "<<ind<<'\n';
  		for (int i=0;i<N;++i)ban[i]=1;
  		dfs(ind, par[ind]);
  		pos = sub[ind];
  		rt = ind;
  		if (pos == 1){
  			answer(0,rt);
  			return;
  		}
  	}else{
  		// cout<<"NO Reroot( "<<ind<<"\n";
  		for (int i=0;i<N;++i){ban[i]=1;sub[i]=0;}
  		blk[ind] = 1;
  		dfs(rt,par[rt]);
  		// for (int i=0;i<N;++i)cout<<sub[i]<<' ';cout<<'\n';
  		pos = sub[rt];
  		if (pos == 1){
  			answer(0,rt);
  			return;
  		}
  	}
  }
  answer(0,rt);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Incorrect 6 ms 2680 KB Output is incorrect: more than 100 calls to ask.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 2744 KB Output is incorrect: more than 100 calls to ask.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 3776 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 2808 KB Output is incorrect: more than 100 calls to ask.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 445 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 398 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -