# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
87991 | Pajaraja | 꿈 (IOI13_dreaming) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "grader.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> g[100001],t[100001];
int maax,maxind,sol[100001],cnt,n,m,l,maxp[100001];
bool vi[100001];
bool lockdown;
void dfsdist(int s,int f,int dist)
{
vi[s]=true;
if(dist>maax)
{
maax=dist;
maxind=s;
}
for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) dfsdist(g[s][i],s,dist+t[s][i]);
}
void dfs(int s,int f,int dist,int ne)
{
if(dist==ne)
{
lockdown=true;
sol[cnt]=maax;
}
for(int i=0;i<g[s].size();i++)
{
if(g[s][i]!=f) dfs(g[s][i],s,dist+t[s][i],ne);
if(lockdown)
{
sol[cnt]=fmin(sol[cnt],fmax(maax-dist,dist));
return;
}
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
int t1,t2,t3;
n=N;
m=M;
l=L;
for(int i=0;i<m;i++)
{
t1=A[i];
t2=B[i];
t3=T[i];
g[t1].push_back(t2);
g[t2].push_back(t1);
t[t1].push_back(t3);
t[t2].push_back(t3);
}
for(int i=0;i<n;i++) if(!vi[i])
{
maax=0;
maxind=i;
dfsdist(i,-1,0);
maax=0;
dfsdist(maxind,-1,0);
maxp[cnt]=maax;
lockdown=false;
dfs(maxind,-1,0,maax);
cnt++;
}
int rez=0;
for(int i=0;i<cnt;i++) rez=fmax(rez,maxp[i]);
sort(sol,sol+cnt);
if(cnt>1)rez=fmax(rez,sol[cnt-1]+l+sol[cnt-2]);
if(cnt>2) rez=fmax(rez,sol[cnt-2]+2*l+sol[cnt-3]);
return rez;
}