#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<cstring>
#include<vector>
#include "dreaming.h"
using namespace std;
#define for1(i,n) for(int i=1;i<=(int)n;i++)
#define for0(i,n) for(int i=0;i<=(int)n;i++)
#define forn(i,n) for(int i=n;i>=1;i--)
#define fo(i,x,y) for(int i=x;i<=(int)y;i++)
#define fr(i,x,y) for(int i=x;i>=(int)y;i--)
#define pb push_back
#define mp make_pair
#define LL long long
const LL Mod=1000*1000*1000+7;
vector<vector<pair<int,int> > > g(100002);
int max1[100002];
int pos[100002];
int max2[100002];
int verHi[100002];
int used[100002];
int ANSWER;
void dfs_fordown(int v,int p)
{
used[v]=1;
for0(j,g[v].size()-1)
{
int to=g[v][j].first;
int len=g[v][j].second;
if(to!=p)
{
dfs_fordown(to,v);
if((max1[to]+len)>=max1[v])
{
max2[v]=max1[v];
max1[v]=(max1[to]+len);
pos[v]=to;
}
else
{
if((max1[to]+len)>max2[v])
max2[v]=max1[to]+len;
}
}
}
}
int dfs_forup(int v,int p,int lenpar)
{
if(p!=-1)
{
if(pos[p]==v)
verHi[v]=max(verHi[p],max2[p])+lenpar;
else
verHi[v]=max(verHi[p],max1[p])+lenpar;
}
for0(j,g[v].size()-1)
{
int to=g[v][j].first;
int len=g[v][j].second;
if(to!=p)
{
dfs_forup(to,v,len);
}
}
//cout<<v<<" "<<verHi[v]<<" "<<max1[v]<<endl;
ANSWER=min(ANSWER,max(verHi[v],max1[v]));
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
for0(i,M-1)
{
g[A[i]].pb({B[i],T[i]});
g[B[i]].pb({A[i],T[i]});
}
vector<int> D;
for0(i,N-1)
{
if(used[i]==0)
{
ANSWER=1000000002;
dfs_fordown(i,-1);
dfs_forup(i,-1,0);
D.push_back(ANSWER);
}
}
int l=D.size();
if(l==1)
return D[0];
if(l==2)
return (D[0]+D[1]+L);
sort(D.begin(),D.end());
int ANS=(D[l-1]+D[l-2]+L);
ANS=max(ANS,D[l-2]+D[l-3]+L+L);
return ANS;
}
/*
12 8 2
0 8 2 5 5 1 1 10
8 2 7 11 1 3 9 6
4 2 4 3 7 1 5 3
*/
Compilation message
dreaming.cpp: In function 'int dfs_forup(int, int, int)':
dreaming.cpp:75:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
12408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
12408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
12408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
7164 KB |
Output is correct |
2 |
Correct |
35 ms |
7288 KB |
Output is correct |
3 |
Correct |
33 ms |
7164 KB |
Output is correct |
4 |
Correct |
35 ms |
7296 KB |
Output is correct |
5 |
Correct |
27 ms |
7168 KB |
Output is correct |
6 |
Correct |
30 ms |
7680 KB |
Output is correct |
7 |
Correct |
33 ms |
7388 KB |
Output is correct |
8 |
Correct |
30 ms |
7168 KB |
Output is correct |
9 |
Correct |
30 ms |
7156 KB |
Output is correct |
10 |
Correct |
30 ms |
7412 KB |
Output is correct |
11 |
Correct |
4 ms |
2688 KB |
Output is correct |
12 |
Correct |
8 ms |
4984 KB |
Output is correct |
13 |
Correct |
9 ms |
5112 KB |
Output is correct |
14 |
Correct |
9 ms |
4940 KB |
Output is correct |
15 |
Correct |
8 ms |
4984 KB |
Output is correct |
16 |
Correct |
8 ms |
4856 KB |
Output is correct |
17 |
Correct |
8 ms |
4092 KB |
Output is correct |
18 |
Correct |
9 ms |
5112 KB |
Output is correct |
19 |
Correct |
9 ms |
4860 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
4 ms |
2816 KB |
Output is correct |
23 |
Correct |
8 ms |
4856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
12408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
12408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |