답안 #30170

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
30170 2017-07-22T20:43:19 Z inqr 꿈 (IOI13_dreaming) C++14
0 / 100
1000 ms 15352 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rt insert
#define st first
#define nd second
#define ll long long
#define pii pair < int , int >
#define DB printf("debug\n");
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define all(x) x.begin() , x.end()
using namespace std;
int n,m,l,ans=-1;
vector < pair < int , int > > ed[150005];
bool in_for[150005];
vector < int > radius;

int maxw,maxwv,dia1,dia2,mincw,mincwv;
vector < int > d1,d2;
void dfs(int vn,int vb,int wn,vector<int>&d){
	//printf("  1:vn=%d vb=%d wn=%d\n",vn,vb,wn);
	if(wn>maxw){
		maxw=wn;
		maxwv=vn;
	}
	in_for[vn]=1;
	d[vn]=wn;
	if(d1[vn]!=1e9&&d2[vn]!=1e9&&max(d1[vn],d2[vn])<mincw){
		mincw=max(d1[vn],d2[vn]);
		mincwv=vn;
	}
	for(int i=0;i<ed[vn].size();i++)
		if(ed[vn][i].st!=vb)
			dfs(ed[vn][i].st,vn,wn+ed[vn][i].nd,d);
}

void for_fn(int rt){
	d1=d2=vector < int >(150005,1e9);
	maxw=maxwv=dia1=dia2=mincwv=-1;mincw=1e9;
	//printf("1:rt=%d\n",rt);
	if(ed[rt].size()==0){
		in_for[rt]=1;
		radius.pb(0);
		return;
	}

	dfs(rt,-1,0,d1);
	dia1=maxwv;maxw=-1;
	ans=max(ans,maxw);

	//printf("2:dia1=%d\n",dia1);
	dfs(dia1,-1,0,d1);
	dia2=maxwv;maxw=-1;

	//printf("2:dia2=%d\n",dia2);
	dfs(dia2,-1,0,d2);

	//printf("rt=%d mincw=%d mincwv=%d\n",rt,mincw,mincwv);
	radius.pb(mincw);
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
 	n=N,m=M,l=L;
	for(int i=0;i<M;i++){
		ed[A[i]].pb(mp(B[i],T[i]));
		ed[B[i]].pb(mp(A[i],T[i]));
	}
	for(int i=0;i<N;i++){
		if(!in_for[i])for_fn(i);
	}
	sort(all(radius));
	reverse(all(radius));
	int rs=radius.size();
	if(rs==1)return ans;
	umax(ans,radius[0]+radius[1]+l);
	if(rs==2)return ans;
	umax(ans,radius[1]+radius[2]+2*l);
	return ans;
}

Compilation message

dreaming.cpp: In function 'void dfs(int, int, int, std::vector<int>&)':
dreaming.cpp:34:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<ed[vn].size();i++)
              ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 84 ms 15352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 84 ms 15352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 84 ms 15352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1076 ms 8348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 84 ms 15352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 84 ms 15352 KB Output isn't correct
2 Halted 0 ms 0 KB -