#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
using lol=long long int;
int dfs(int u,const vector<vector<pair<int,int> > >& g,int p=-1)
{
int mx=0;
for(auto [v,w]:g[u])
{
if(v==p) continue;
mx=max(mx,w+dfs(v,g,u));
}
return mx;
}
int getrep(int u,const vector<vector<pair<int,int> > >& g,vector<bool>& vis,const vector<int>& D)
{
vis[u]=true;
int mn=D[u];
for(auto [v,w]:g[u])
{
if(vis[v]) continue;
mn=min(mn,getrep(v,g,vis,D));
}
return mn;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
vector<vector<pair<int,int> > > g(N);
for(int i=0;i<M;i++)
{
g[A[i]].push_back({B[i],T[i]});
g[B[i]].push_back({A[i],T[i]});
}
vector<int> D(N);
vector<int> reps;
for(int i=0;i<N;i++)
{
D[i]=dfs(i,g);
}
vector<bool> vis(N,false);
for(int i=0;i<N;i++)
{
if(vis[i]) continue;
reps.push_back(getrep(i,g,vis,D));
}
sort(reps.rbegin(),reps.rend());
int ans=reps[0];
if(reps.size()>1) ans=max(ans,L+reps[0]+reps[1]);
if(reps.size()>2) ans=max(ans,2*L+reps[1]+reps[2]);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1094 ms |
12780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1094 ms |
12780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
5952 KB |
Output is correct |
2 |
Correct |
26 ms |
6016 KB |
Output is correct |
3 |
Correct |
28 ms |
5940 KB |
Output is correct |
4 |
Correct |
25 ms |
6004 KB |
Output is correct |
5 |
Correct |
28 ms |
5936 KB |
Output is correct |
6 |
Correct |
26 ms |
6480 KB |
Output is correct |
7 |
Correct |
26 ms |
6156 KB |
Output is correct |
8 |
Correct |
26 ms |
5884 KB |
Output is correct |
9 |
Correct |
25 ms |
5836 KB |
Output is correct |
10 |
Correct |
32 ms |
6184 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
6 ms |
3656 KB |
Output is correct |
13 |
Correct |
6 ms |
3656 KB |
Output is correct |
14 |
Correct |
5 ms |
3656 KB |
Output is correct |
15 |
Correct |
5 ms |
3656 KB |
Output is correct |
16 |
Correct |
5 ms |
3656 KB |
Output is correct |
17 |
Correct |
5 ms |
3656 KB |
Output is correct |
18 |
Correct |
5 ms |
3656 KB |
Output is correct |
19 |
Correct |
5 ms |
3656 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
5 ms |
3656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1094 ms |
12780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |