#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+1;
vector<pair<int,int>>adj[MAXN];
bool vis[MAXN];
int dep[MAXN],p[MAXN];
vector<int>cc;
int mn = 2e9,ans = 0;
void dfs(int v,int u){
vis[v] = 1;
cc.push_back(v);
for(auto x:adj[v]){
if(x.first != u){
dfs(x.first,v);
dep[v] = max(dep[v],dep[x.first] + x.second);
}
}
}
void dfs2(int v,int u){
for(auto x:adj[v]){
if(x.first != u){
dfs(x.first,v);
dep[v] = max(dep[v],dep[x.first] + x.second);
}
}
}
void get(int v,int u){
multiset<int,greater<int>>s;
s.insert(p[v]);
for(auto x:adj[v]){
if(x.first == u)continue;
s.insert(dep[x.first] + x.second);
}
int mx = max(p[v],dep[v]);
mn = min(mx,mn);
for(auto x:adj[v]){
if(x.first == u)continue;
s.erase(s.find(dep[x.first] + x.second));
p[x.first] = *s.begin() + x.second;
get(x.first,v);
s.insert(dep[x.first] + x.second);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for(int i=0;i<M;i++){
adj[A[i]].push_back({B[i],T[i]});
adj[B[i]].push_back({A[i],T[i]});
}
vector<int>v;
for(int i=0;i<N;i++){
if(!vis[i]){
cc.clear();
dfs(i,-1);
int c =0;
for(auto x:adj[i]){
int k = dep[x.first] + x.second;
ans = max(ans,c + k);
c = max(c,k);
}
mn = 1e9;
/*
for(int x:cc){
for(int j=0;j<N;j++)dep[j] = p[j] = 0;
dfs2(x,-1);
mn = min(mn,dep[x]);
}*/
v.push_back(mn);
//cout<<i<<" "<<mn<<'\n';
}
}
//for(int i=0;i<N;i++)cout<<dep[i]<<" ";
//cout<<'\n';
//for(int i=0;i<N;i++)cout<<p[i]<<" ";
//cout<<'\n';
sort(v.begin(),v.end(),greater<int>());
if(v.size()>=2)ans = max(ans,v[0] + v[1] + L);
if(v.size()>=3)ans = max(ans,v[1] + v[2] + 2*L);
return ans;
}
/*
int main(){
int n,m,l;
cin>>n>>m>>l;
int a[m],b[m],t[m];
for(int i=0;i<m;i++)cin>>a[i]>>b[i]>>t[i];
cout<<travelTime(n,m,l,a,b,t);
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
11528 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
11528 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
5720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
11528 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |