#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<grp[i].size();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])
| ^
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:56:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int k=0;k<grp[i].size();k++)
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
14104 KB |
Output is correct |
2 |
Correct |
33 ms |
14072 KB |
Output is correct |
3 |
Correct |
23 ms |
11456 KB |
Output is correct |
4 |
Correct |
6 ms |
6356 KB |
Output is correct |
5 |
Correct |
6 ms |
5716 KB |
Output is correct |
6 |
Correct |
10 ms |
7108 KB |
Output is correct |
7 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Incorrect |
2 ms |
5004 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
14104 KB |
Output is correct |
2 |
Correct |
33 ms |
14072 KB |
Output is correct |
3 |
Correct |
23 ms |
11456 KB |
Output is correct |
4 |
Correct |
6 ms |
6356 KB |
Output is correct |
5 |
Correct |
6 ms |
5716 KB |
Output is correct |
6 |
Correct |
10 ms |
7108 KB |
Output is correct |
7 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
9840 KB |
Output is correct |
2 |
Correct |
20 ms |
9872 KB |
Output is correct |
3 |
Correct |
20 ms |
9812 KB |
Output is correct |
4 |
Correct |
18 ms |
9812 KB |
Output is correct |
5 |
Correct |
18 ms |
9812 KB |
Output is correct |
6 |
Correct |
27 ms |
10084 KB |
Output is correct |
7 |
Correct |
23 ms |
9956 KB |
Output is correct |
8 |
Correct |
19 ms |
9716 KB |
Output is correct |
9 |
Correct |
17 ms |
9684 KB |
Output is correct |
10 |
Correct |
20 ms |
10024 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
7 ms |
8660 KB |
Output is correct |
13 |
Correct |
7 ms |
8660 KB |
Output is correct |
14 |
Correct |
7 ms |
8660 KB |
Output is correct |
15 |
Correct |
7 ms |
8660 KB |
Output is correct |
16 |
Correct |
7 ms |
8660 KB |
Output is correct |
17 |
Correct |
8 ms |
8660 KB |
Output is correct |
18 |
Correct |
7 ms |
8724 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Incorrect |
2 ms |
5004 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
14104 KB |
Output is correct |
2 |
Correct |
33 ms |
14072 KB |
Output is correct |
3 |
Correct |
23 ms |
11456 KB |
Output is correct |
4 |
Correct |
6 ms |
6356 KB |
Output is correct |
5 |
Correct |
6 ms |
5716 KB |
Output is correct |
6 |
Correct |
10 ms |
7108 KB |
Output is correct |
7 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |