답안 #286812

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
286812 2020-08-31T03:37:54 Z TMJN 꿈 (IOI13_dreaming) C++17
18 / 100
63 ms 13172 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

struct edge{
	int to,dist;
};

bool vis[100000];
int D[100000],DD[100000],DDD[100000];
vector<edge>E[100000];

void dfs0(int x,int from,vector<int>&v){
	vis[x]=true;
	v.push_back(x);
	for(edge e:E[x]){
		if(e.to==from)continue;
		D[e.to]=D[x]+e.dist;
		dfs0(e.to,x,v);
	}
}

void dfs1(int x,int from){
	for(edge e:E[x]){
		if(e.to==from)continue;
		DD[e.to]=DD[x]+e.dist;
		dfs1(e.to,x);
	}
}
void dfs2(int x,int from){
	for(edge e:E[x]){
		if(e.to==from)continue;
		DDD[e.to]=DDD[x]+e.dist;
		dfs2(e.to,x);
	}
}


int travelTime(int N, int M, int L, int a[], int b[], int d[]) {
	for(int i=0;i<M;i++){
		E[a[i]].push_back({b[i],d[i]});
		E[b[i]].push_back({a[i],d[i]});
	}
	vector<int>v;
	for(int i=0;i<N;i++){
		if(!vis[i]){
			vector<int>V;
			dfs0(i,i,V);
			pair<int,int>p={-1,-1};
			for(int j:V){
				p=max(p,{D[j],j});
			}
			dfs1(p.second,p.second);
			pair<int,int>pp={-1,-1};
			for(int j:V){
				pp=max(pp,{DD[j],j});
			}
			dfs2(pp.second,pp.second);
			int mn=2000000000;
			for(int j:V){
				mn=min(mn,max(DD[j],DDD[j]));
			}
			v.push_back(mn);
		}
	}
	sort(v.begin(),v.end(),greater<>());
	if(v.size()==1){
		return v.front();
	}
	else if(v.size()==2){
		return v[0]+v[1]+L;
	}
	else{
		return max(v[0]+v[1]+L,v[1]+v[2]+L+L);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 13172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 13172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 13172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 6964 KB Output is correct
2 Correct 36 ms 7032 KB Output is correct
3 Correct 40 ms 7032 KB Output is correct
4 Correct 35 ms 6964 KB Output is correct
5 Correct 35 ms 7032 KB Output is correct
6 Correct 36 ms 7552 KB Output is correct
7 Correct 35 ms 7160 KB Output is correct
8 Correct 33 ms 6904 KB Output is correct
9 Correct 32 ms 6900 KB Output is correct
10 Correct 35 ms 7144 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 10 ms 4348 KB Output is correct
13 Correct 10 ms 4476 KB Output is correct
14 Correct 10 ms 4348 KB Output is correct
15 Correct 10 ms 4348 KB Output is correct
16 Correct 10 ms 4220 KB Output is correct
17 Correct 10 ms 3708 KB Output is correct
18 Correct 11 ms 4476 KB Output is correct
19 Correct 10 ms 4348 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 10 ms 4348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 13172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 13172 KB Output isn't correct
2 Halted 0 ms 0 KB -