답안 #262246

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
262246 2020-08-12T14:25:14 Z eohomegrownapps 꿈 (IOI13_dreaming) C++14
18 / 100
59 ms 11384 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

vector<vector<pair<int,int>>> adjlist; //ind,val
int n;

vector<bool> visited;
vector<int> parent;
vector<int> depth;

int fdist = 0;
int f_ind = 0;
int INF = 1e9;

void getFurthest(int ind, int par){
	//cout<<ind<<' '<<par<<'\n';
	visited[ind]=true;
	parent[ind]=par;
	for (auto p : adjlist[ind]){
		//cout<<"proc "<<p.first<<' '<<p.second<<'\n';
		if (p.first==par){continue;}
		depth[p.first]=depth[ind]+p.second;
		if (depth[p.first]>fdist){
			fdist=depth[p.first];
			f_ind=p.first;
		}
		getFurthest(p.first,ind);
	}
}


pair<int,int> getDiamDepth(int ind){
	//cout<<"check "<<ind<<'\n';
	fdist=0;f_ind=ind;
	parent[ind]=-1;
	getFurthest(ind,-1);
	int ftmp = f_ind;
	fdist=0;f_ind=ftmp;
	parent[ftmp]=-1;depth[ftmp]=0;
	getFurthest(ftmp,-1);
	//find min depth
	int cur = f_ind;
	int md = INF;
	while (cur!=-1){
		md = min(md, max(depth[cur],fdist-depth[cur]));
		cur=parent[cur];
	}
	//cout<<ind<<": "<<fdist<<' '<<md<<'\n';
	return {fdist,md};
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n=N;
    adjlist.resize(n);
    for (int i = 0; i<M; i++){
    	adjlist[A[i]].push_back({B[i],T[i]});
    	adjlist[B[i]].push_back({A[i],T[i]});
    }
    visited.resize(n);
    parent.resize(n,-1);
    depth.resize(n);
    int mindist = INF;
    int maxd = -1;
    int smaxd = -1;
    int tmaxd = -1;
    for (int i = 0; i<n; i++){
    	if (visited[i]){continue;}
    	auto pii = getDiamDepth(i);
    	mindist = min(mindist, pii.first);
    	if (pii.second>=maxd){
    		tmaxd=smaxd;
    		smaxd=maxd;
    		maxd=pii.second;
    	} else if (pii.second>=smaxd){
    		tmaxd=smaxd;
    		smaxd=pii.second;
    	} else if (pii.second>=tmaxd){
    		tmaxd=pii.second;
    	}
    }
    if (tmaxd!=-1){
    	mindist=max(mindist,tmaxd+smaxd+2*L);
    }
    if (smaxd!=-1){
    	mindist=max(mindist,maxd+smaxd+L);
    }
    return mindist;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 11384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 11384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 11384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 5632 KB Output is correct
2 Correct 25 ms 5576 KB Output is correct
3 Correct 24 ms 5632 KB Output is correct
4 Correct 30 ms 5632 KB Output is correct
5 Correct 27 ms 5632 KB Output is correct
6 Correct 26 ms 6016 KB Output is correct
7 Correct 26 ms 5888 KB Output is correct
8 Correct 31 ms 5504 KB Output is correct
9 Correct 25 ms 5504 KB Output is correct
10 Correct 35 ms 5760 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 5 ms 3456 KB Output is correct
13 Correct 5 ms 3456 KB Output is correct
14 Correct 6 ms 3456 KB Output is correct
15 Correct 5 ms 3456 KB Output is correct
16 Correct 5 ms 3456 KB Output is correct
17 Correct 5 ms 3456 KB Output is correct
18 Correct 6 ms 3584 KB Output is correct
19 Correct 6 ms 3456 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 5 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 11384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 11384 KB Output isn't correct
2 Halted 0 ms 0 KB -