답안 #17351

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
17351 2015-11-24T22:36:43 Z comet 꿈 (IOI13_dreaming) C++
14 / 100
62 ms 11896 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 Max,len[100000],ans;
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){
	Max=min(Max,max(h,max(subsz[v],subsz2[v])));
	ans=max(ans,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]){
			Max=1e9;
			dfs2(i,i,0);
			len[i]=Max;
			s.pb(pp(len[i],i));
		}
	}

	sort(s.begin(),s.end());
	if(s.size()==1)return max(ans,s[0].first);
	return max(ans,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:40:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<path[v].size();i++){
              ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 11896 KB Output is correct
2 Correct 56 ms 11512 KB Output is correct
3 Correct 43 ms 9336 KB Output is correct
4 Correct 9 ms 2048 KB Output is correct
5 Correct 7 ms 1408 KB Output is correct
6 Correct 14 ms 2944 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 27 ms 5248 KB Output is correct
9 Correct 34 ms 7672 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 53 ms 8824 KB Output is correct
12 Correct 62 ms 10232 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 11896 KB Output is correct
2 Correct 56 ms 11512 KB Output is correct
3 Correct 43 ms 9336 KB Output is correct
4 Correct 9 ms 2048 KB Output is correct
5 Correct 7 ms 1408 KB Output is correct
6 Correct 14 ms 2944 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 27 ms 5248 KB Output is correct
9 Correct 34 ms 7672 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 53 ms 8824 KB Output is correct
12 Correct 62 ms 10232 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 304 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Incorrect 2 ms 356 KB Output isn't correct
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 11896 KB Output is correct
2 Correct 56 ms 11512 KB Output is correct
3 Correct 43 ms 9336 KB Output is correct
4 Correct 9 ms 2048 KB Output is correct
5 Correct 7 ms 1408 KB Output is correct
6 Correct 14 ms 2944 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 27 ms 5248 KB Output is correct
9 Correct 34 ms 7672 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 53 ms 8824 KB Output is correct
12 Correct 62 ms 10232 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 304 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Incorrect 2 ms 356 KB Output isn't correct
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 7412 KB Output is correct
2 Incorrect 35 ms 7420 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 11896 KB Output is correct
2 Correct 56 ms 11512 KB Output is correct
3 Correct 43 ms 9336 KB Output is correct
4 Correct 9 ms 2048 KB Output is correct
5 Correct 7 ms 1408 KB Output is correct
6 Correct 14 ms 2944 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 27 ms 5248 KB Output is correct
9 Correct 34 ms 7672 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 53 ms 8824 KB Output is correct
12 Correct 62 ms 10232 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 4 ms 512 KB Output is correct
16 Correct 3 ms 640 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 3 ms 640 KB Output is correct
20 Incorrect 2 ms 384 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 11896 KB Output is correct
2 Correct 56 ms 11512 KB Output is correct
3 Correct 43 ms 9336 KB Output is correct
4 Correct 9 ms 2048 KB Output is correct
5 Correct 7 ms 1408 KB Output is correct
6 Correct 14 ms 2944 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 27 ms 5248 KB Output is correct
9 Correct 34 ms 7672 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 53 ms 8824 KB Output is correct
12 Correct 62 ms 10232 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 304 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Incorrect 2 ms 356 KB Output isn't correct
31 Halted 0 ms 0 KB -