#include "dreaming.cpp"
#include<bits/stdc++.h>
using namespace std;
const long long maxn=100000+10;
struct yal{
long long u,v,w;
long long getad(long long fu){
return (u^v^fu);
}
}alle[maxn];
long long n,m,l,mainres=0,vis[maxn];
vector<long long>adj[maxn];
pair<long long,long long>mx[maxn];
pair<int,int>comp(pair<int,int>a,int b){
if(b>a.first){
a.first=b;
if(a.first>a.second){
swap(a.first,a.second);
}
}
return a;
}
void dfsdown(long long u,long long par=-1){
mx[u]=make_pair(0,0);
for(auto x:adj[u]){
long long v=alle[x].getad(u);
if(v==par){
continue;
}
dfsdown(v,u);
mx[u]=comp(mx[u],mx[v].second+alle[x].w);
}
return ;
}
void dfsup(long long u,long long par=-1,long long l=-1){
mx[u]=comp(mx[u],l);
mainres=max(mainres,mx[u].first+mx[u].second);
for(auto x:adj[u]){
long long v=alle[x].getad(u);
if(v==par){
continue;
}
long long z=mx[u].second;
if(mx[u].second==mx[v].second+alle[x].w){
z=mx[u].first;
}
dfsup(v,u,z);
}
}
long long get(long long u,long long par=-1){
long long ret=u;
for(auto x:adj[u]){
long long v=alle[x].getad(u);
if(v==par){
continue;
}
long long r=get(v,u);
if(mx[ret].second>mx[r].second){
ret=r;
}
}
return ret;
}
long long calc(long long u){
dfsdown(u);
dfsup(u);
return get(u);
}
long long travelTime(long long N, long long M, long long L, long long A[], long long B[], long long T[]) {
n=N;
m=M;
l=L;
for(long long i=0;i<m;i++){
alle[i].u=A[i];
alle[i].v=B[i];
alle[i].w=T[i];
adj[alle[i].u].push_back(i);
adj[alle[i].v].push_back(i);
}
vector<long long>alls;
for(long long i=1;i<=n;i++){
if(vis[i]==0){
alls.push_back(calc(i));
}
}
sort(alls.rbegin(),alls.rend());
if((long long)alls.size()==2){
mainres=max(mainres,alls[0]+alls[1]+l);
}
if((long long)alls.size()>=3){
mainres=max(mainres,alls[0]+alls[1]+l);
mainres=max(mainres,alls[1]+alls[2]+2*l);
}
return mainres;
}
Compilation message
dreaming.cpp:1:10: fatal error: dreaming.cpp: No such file or directory
1 | #include "dreaming.cpp"
| ^~~~~~~~~~~~~~
compilation terminated.