Submission #297978

#TimeUsernameProblemLanguageResultExecution timeMemory
297978HemimorDreaming (IOI13_dreaming)C++14
18 / 100
67 ms15096 KiB
#include "dreaming.h"
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vvp g;
vi b;

P dfs(int v,int pr=-1,int d=0){
	b[v]=d;
	P tmp={d,v};
	for(auto p:g[v]){
		int u=p.first;
		if(u!=pr) tmp=max(tmp,dfs(u,v,d+p.second));
	}
	return tmp;
}

int DFS(int v,int pr=-1,int d=0){
	int tmp=max(d,b[v]);
	for(auto p:g[v]){
		int u=p.first;
		if(u!=pr) tmp=min(tmp,DFS(u,v,d+p.second));
	}
	return tmp;
}

int f(int v){
	v=dfs(v).second;
	int u=dfs(v).second;
	return DFS(u);
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	n=N;
	g=vvp(n);
	b=vi(n,-1);
	for(int i=0;i<M;i++){
		int u=A[i],v=B[i];
		g[u].push_back({v,T[i]});
		g[v].push_back({u,T[i]});
	}
	vi a;
	for(int i=0;i<n;i++) if(b[i]<0) a.push_back(f(i));
	sort(a.rbegin(),a.rend());
	int m=a.size();
	if(m==1) return a[0];
	if(m==2) return a[0]+a[1]+L;
	int res=inf;
	res=min(res,max(a[0]+a[1],a[1]+a[2]+L)+L);
	res=min(res,max(a[1]+a[0],a[0]+a[2]+L)+L);
	res=min(res,max(a[2]+a[0],a[0]+a[1]+L)+L);
	return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...