#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<M;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])
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
14156 KB |
Output is correct |
2 |
Correct |
36 ms |
15280 KB |
Output is correct |
3 |
Correct |
25 ms |
12404 KB |
Output is correct |
4 |
Correct |
7 ms |
6612 KB |
Output is correct |
5 |
Correct |
6 ms |
5844 KB |
Output is correct |
6 |
Correct |
11 ms |
7380 KB |
Output is correct |
7 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
5012 KB |
Output is correct |
3 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
14156 KB |
Output is correct |
2 |
Correct |
36 ms |
15280 KB |
Output is correct |
3 |
Correct |
25 ms |
12404 KB |
Output is correct |
4 |
Correct |
7 ms |
6612 KB |
Output is correct |
5 |
Correct |
6 ms |
5844 KB |
Output is correct |
6 |
Correct |
11 ms |
7380 KB |
Output is correct |
7 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
9812 KB |
Output is correct |
2 |
Correct |
26 ms |
10340 KB |
Output is correct |
3 |
Correct |
21 ms |
10260 KB |
Output is correct |
4 |
Correct |
20 ms |
10280 KB |
Output is correct |
5 |
Correct |
19 ms |
10144 KB |
Output is correct |
6 |
Correct |
20 ms |
10508 KB |
Output is correct |
7 |
Correct |
21 ms |
10416 KB |
Output is correct |
8 |
Correct |
19 ms |
10060 KB |
Output is correct |
9 |
Correct |
19 ms |
10096 KB |
Output is correct |
10 |
Correct |
19 ms |
10396 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
7 ms |
8660 KB |
Output is correct |
13 |
Correct |
9 ms |
8660 KB |
Output is correct |
14 |
Correct |
10 ms |
8660 KB |
Output is correct |
15 |
Correct |
10 ms |
8660 KB |
Output is correct |
16 |
Correct |
7 ms |
8660 KB |
Output is correct |
17 |
Correct |
7 ms |
8660 KB |
Output is correct |
18 |
Correct |
7 ms |
8660 KB |
Output is correct |
19 |
Correct |
7 ms |
8660 KB |
Output is correct |
20 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
5012 KB |
Output is correct |
3 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
14156 KB |
Output is correct |
2 |
Correct |
36 ms |
15280 KB |
Output is correct |
3 |
Correct |
25 ms |
12404 KB |
Output is correct |
4 |
Correct |
7 ms |
6612 KB |
Output is correct |
5 |
Correct |
6 ms |
5844 KB |
Output is correct |
6 |
Correct |
11 ms |
7380 KB |
Output is correct |
7 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |