#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
struct cell
{
int to,cost;
};
int n,m,l,a1[100005],a2[100005],a3[100005],used[100005],ma[100005],sma[100005],a,in[100005],otg[100005],costin[100005];
vector<cell>v[100005];
void dfs(int beg)
{
used[beg]=1;
int w;
for(int i=0;i<(int)(v[beg].size());i++)
{
w=v[beg][i].to;
if(!used[w])
{
dfs(w);
if(ma[beg]<ma[w]+v[beg][i].cost)
{
in[beg]=w;
costin[beg]=v[beg][i].cost;
sma[beg]=ma[beg];
ma[beg]=ma[w]+v[beg][i].cost;
}
else if(sma[beg]<ma[w]+v[beg][i].cost)
{
sma[beg]=ma[w]+v[beg][i].cost;
}
}
}
}
void find_ma(int beg,int izm,int par)
{
if(beg==par)return;
if(izm>ma[beg])
{
int g=izm;
g=min(izm,ma[par]);
otg[beg]=g;
return;
}
find_ma(in[beg],max(izm,sma[beg])+costin[beg],beg);
}
void fil(int beg)
{
int w;
used[beg]=1;
for(int i=0;i<(int)(v[beg].size());i++)
{
w=v[beg][i].to;
if(!used[w])
{
fil(w);
}
}
}
int travelTime(int n,int m,int l,int a1[],int a2[],int a3[])
//void read()
{
//cin>>n>>m>>l;
cell h;
for(int i=1;i<=m;i++)
{
//cin>>a1[i]>>a2[i]>>a3[i];
h.to=a2[i];
h.cost=a3[i];
v[a1[i]].push_back(h);
h.to=a1[i];
v[a2[i]].push_back(h);
}
for(int i=1;i<=n;i++)
{
if(!used[i])
{
dfs(i);
}
}
memset(used,0,sizeof(used));
for(int i=1;i<=n;i++)
{
if(!used[i])
{
find_ma(i,0,0);
fil(i);
}
}
sort(otg+1,otg+n+1);
//if(m!=n-2)cout<<max(otg[n],otg[n-2]+l)+otg[n-1]+l<<endl;
//else cout<<otg[n]+otg[n-1]+l;
int aa=0;
for(int i=1;i<=n;i++)
{
aa=max(aa,ma[i],sma[i]);
}
if(m!=n-2)return max(aa,max(otg[n],otg[n-2]+l)+otg[n-1]+l);
else return max(aa,otg[n]+otg[n-1]+l);
}
/*int main()
{
speed();
read();
return 0;
}
*/
Compilation message
In file included from /usr/include/c++/10/bits/char_traits.h:39,
from /usr/include/c++/10/ios:40,
from /usr/include/c++/10/istream:38,
from /usr/include/c++/10/sstream:38,
from /usr/include/c++/10/complex:45,
from /usr/include/c++/10/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
from dreaming.cpp:2:
/usr/include/c++/10/bits/stl_algobase.h: In instantiation of 'constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare) [with _Tp = int; _Compare = int]':
dreaming.cpp:101:31: required from here
/usr/include/c++/10/bits/stl_algobase.h:303:17: error: '__comp' cannot be used as a function
303 | if (__comp(__a, __b))
| ~~~~~~^~~~~~~~~~