#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
vector<pii> V[100008];
vector<int> grp[100008];
bool vis1[100008];
bool vis2[100008];
int mxdis[100008];
void ddfs(int prev,int cur,int dis)
{
mxdis[cur]=max(mxdis[cur],dis);
for(auto [w,v]:V[cur])
{
if(v!=prev)
{
ddfs(cur,v,dis+w);
}
}
}
void gdfs(int prev,int cur,int g)
{
vis1[cur]=true;
grp[g].pb(cur);
for(auto [w,v]:V[cur])
{
if(v!=prev)
gdfs(cur,v,g);
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
int u,v,w;
for(int i=0;i<N;i++)
{
u=A[i];
v=B[i];
w=T[i];
V[u].pb({w,v});
V[v].pb({w,u});
}
for(int i=0;i<N;i++)
{
if(vis1[i])continue;
gdfs(-1,i,i);
}
int mx1=-8,mx2=-8,mx3=-8,ans=0;
for(int i=0;i<N;i++)
{
if(grp[i].empty())continue;
int prev=N;
for(int k=0;k<3;k++)
{
int cur=N;
for(auto v:grp[i])
{
if(!vis2[v]&&mxdis[v]>=mxdis[prev]&&mxdis[v]>=mxdis[cur])
cur=v;
}
if(cur==N)/// <3
break;
ddfs(N,cur,0);
vis2[cur]=true;
prev=cur;
}
int mn=INT_MAX;//shortest from longest
for(auto v:grp[i])
{
mn=min(mxdis[v],mn);
ans=max(ans,mxdis[v]);
}
if(mn>=mx1)
mx3=mx2,mx2=mx1,mx1=mn;
else if(mn>=mx2)
mx3=mx2,mx2=mn;
else if(mn>=mx3)
mx3=mn;
}
ans=max({ans,mx1+mx2+L,mx2+mx3+2*L});
return ans;
}
Compilation message
dreaming.cpp: In function 'void ddfs(int, int, int)':
dreaming.cpp:16:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
16 | for(auto [w,v]:V[cur])
| ^
dreaming.cpp: In function 'void gdfs(int, int, int)':
dreaming.cpp:28:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
28 | for(auto [w,v]:V[cur])
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
89 ms |
17228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
89 ms |
17228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1055 ms |
8960 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
89 ms |
17228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |