# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1170337 | rayan_bd | 꿈 (IOI13_dreaming) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define show(n) cout<<n<<'\n'
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
const int INF = -1e9;
const int mxN = 1e5 + 5;
vector<pair<int,int>> adj[mxN];
int compo[mxN],curr=0;
void add_edge(int u,int v,int w){
adj[u].pb({v,w});
adj[v].pb({u,w});
}
int dfs(int u,int par,int w){
if(adj[u].size()==1) return w;
if(curr==0) compo[u]=curr;
int mx=0;
for(auto it:adj[u]){
if(it.fi^par) mx=max(mx,dfs(it.fi,u,w+it.se));
}
return mx;
}
int travelTime(int N,int M,int L,int A[],int B[],int T[]){
for(int i=0;i<N;++i) adj[i].clear(),compo[i]=curr=0ll;
for(int i=0;i<N;++i) add_edge(A[i],B[i],T[i]);
int cost1=INF,cost2=INF;
dfs(0,-1,0); ++curr;
for(int i=0;i<N;++i){
if(compo[i]==0){
cost1=min(cost1,dfs(i,-1,0));
}else{
cost2=min(cost1,dfs(i,-1,0));
}
}
return cost1+cost2+L;
}