답안 #17350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
17350 2015-11-24T22:29:57 Z comet 꿈 (IOI13_dreaming) C++
0 / 100
76 ms 11968 KB
#include <cstdio>
#include <algorithm>
#include <vector>
#include "dreaming.h"
using namespace std;
typedef pair<int,int> pp;
typedef vector<pp> vec;
typedef vector<vec> mat;
#define pb push_back

int N;
int subsz[100000],subsz2[100000];
int vi[100000],vi2[100000];
int ans,len[100000];
bool chk[100000];
vec s;
mat path;

void dfs(int v,int p){
	chk[v]=1;
	for(int i=0;i<path[v].size();i++){
		int u=path[v][i].first;
		int c=path[v][i].second;
		if(u==p)continue;
		dfs(u,v);
		int t=subsz[u]+c;
		if(subsz[v]<t){
			subsz2[v]=subsz[v];vi2[v]=vi[v];
			subsz[v]=t;vi[v]=u;
		}else if(subsz2[v]<t){
			subsz2[v]=t;vi2[v]=u;
		}
	}
}

void dfs2(int v,int p,int h){
	ans=min(ans,max(h,max(subsz[v],subsz2[v])));
	chk[v]=0;
	for(int i=0;i<path[v].size();i++){
		int u=path[v][i].first;
		int c=path[v][i].second;
		if(u==p)continue;
		if(u==vi[v]){
			dfs2(u,v,max(h,subsz2[v])+c);
		}else if(u==vi2[v]){
			dfs2(u,v,max(h,subsz[v])+c);
		}
	}
}

int travelTime(int N_, int M, int L, int A[], int B[], int T[]) {
	N=N_;
	path.assign(N+1,vec());
	for(int i=0;i<M;i++){
		path[A[i]].pb(pp(B[i],T[i]));
		path[B[i]].pb(pp(A[i],T[i]));
	}
	for(int i=0;i<N;i++){
		if(!chk[i]){
			dfs(i,i);
		}
	}

	for(int i=0;i<N;i++){
		if(chk[i]){
			ans=1e9;
			dfs2(i,i,0);
			len[i]=ans;
			s.pb(pp(len[i],i));
		}
	}

	sort(s.begin(),s.end());
	if(s.size()==1)return s[0].first;
	return s[s.size()-1].first+s[s.size()-2].first+L;
}

Compilation message

dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:21:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<path[v].size();i++){
              ~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfs2(int, int, int)':
dreaming.cpp:39:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<path[v].size();i++){
              ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 76 ms 11968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 76 ms 11968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 76 ms 11968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 7324 KB Output is correct
2 Incorrect 36 ms 7412 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 76 ms 11968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 76 ms 11968 KB Output isn't correct
2 Halted 0 ms 0 KB -