#include "dreaming.h"
#include <vector>
#include <stdio.h>
using namespace std;
vector < pair < long long , long long > > Next[100005];
bool have[100005]={0};
long long a=0,b=0,c=0,t=0,big=0,bb=0,where;
void F(long long here,long long con)
{
if(con>=big)
{
big=con;
where=here;
}
have[here]=1;
for(auto i:Next[here]) if(!have[i.first]) F(i.first,con+i.second);
}
void F2(long long here,long long Father,long long con)
{
t=min(t,max(con,big-con));
for(auto i:Next[here]) if(i.first!=Father) F2(i.first,here,con+i.second);
}
void F3(long long here,long long Father,long long con)
{
big=max(big,con);
for(auto i:Next[here]) if(i.first!=Father) F3(i.first,here,con+i.second);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
long long i,how=0;
for(i=0;i<M;i++)
{
Next[A[i]].push_back(make_pair((long long)B[i],(long long)T[i]));
Next[B[i]].push_back(make_pair((long long)A[i],(long long)T[i]));
}
for(i=0;i<N;i++)
{
if(!have[i])
{
how++;
big=0;
where=0;
F(i,0);
F3(where,-1,0);
bb=max(bb,big);
t=1e9;
F2(where,-1,0);
if(t>=a)
{
c=b;
b=a;
a=t;
}
else if(t>=b)
{
c=b;
b=t;
}
else if(t>=c) c=t;
}
}
//printf("%d %d %d %d %d\n",how,bb,a,b,c);
if(how>=2) bb=max(bb,a+b+L);
if(how>=3) bb=max(bb,b+c+2*L);
return (int) bb;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
12408 KB |
Output is correct |
2 |
Correct |
59 ms |
12412 KB |
Output is correct |
3 |
Correct |
40 ms |
9080 KB |
Output is correct |
4 |
Correct |
9 ms |
4096 KB |
Output is correct |
5 |
Correct |
8 ms |
3584 KB |
Output is correct |
6 |
Correct |
16 ms |
4992 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
40 ms |
6392 KB |
Output is correct |
9 |
Correct |
43 ms |
7804 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
69 ms |
9464 KB |
Output is correct |
12 |
Correct |
81 ms |
11000 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
12408 KB |
Output is correct |
2 |
Correct |
59 ms |
12412 KB |
Output is correct |
3 |
Correct |
40 ms |
9080 KB |
Output is correct |
4 |
Correct |
9 ms |
4096 KB |
Output is correct |
5 |
Correct |
8 ms |
3584 KB |
Output is correct |
6 |
Correct |
16 ms |
4992 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
40 ms |
6392 KB |
Output is correct |
9 |
Correct |
43 ms |
7804 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
69 ms |
9464 KB |
Output is correct |
12 |
Correct |
81 ms |
11000 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
2 ms |
2688 KB |
Output is correct |
16 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
12408 KB |
Output is correct |
2 |
Correct |
59 ms |
12412 KB |
Output is correct |
3 |
Correct |
40 ms |
9080 KB |
Output is correct |
4 |
Correct |
9 ms |
4096 KB |
Output is correct |
5 |
Correct |
8 ms |
3584 KB |
Output is correct |
6 |
Correct |
16 ms |
4992 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
40 ms |
6392 KB |
Output is correct |
9 |
Correct |
43 ms |
7804 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
69 ms |
9464 KB |
Output is correct |
12 |
Correct |
81 ms |
11000 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
2 ms |
2688 KB |
Output is correct |
16 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
5008 KB |
Output is correct |
2 |
Correct |
24 ms |
5120 KB |
Output is correct |
3 |
Correct |
25 ms |
5248 KB |
Output is correct |
4 |
Correct |
23 ms |
5112 KB |
Output is correct |
5 |
Correct |
23 ms |
5112 KB |
Output is correct |
6 |
Correct |
25 ms |
5248 KB |
Output is correct |
7 |
Correct |
24 ms |
5120 KB |
Output is correct |
8 |
Correct |
23 ms |
4992 KB |
Output is correct |
9 |
Correct |
22 ms |
4992 KB |
Output is correct |
10 |
Correct |
24 ms |
5120 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
4 ms |
2816 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
4 ms |
2816 KB |
Output is correct |
15 |
Correct |
4 ms |
2816 KB |
Output is correct |
16 |
Correct |
4 ms |
2816 KB |
Output is correct |
17 |
Correct |
3 ms |
2816 KB |
Output is correct |
18 |
Correct |
4 ms |
2816 KB |
Output is correct |
19 |
Correct |
4 ms |
2816 KB |
Output is correct |
20 |
Correct |
2 ms |
2688 KB |
Output is correct |
21 |
Correct |
2 ms |
2688 KB |
Output is correct |
22 |
Correct |
2 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
12408 KB |
Output is correct |
2 |
Correct |
59 ms |
12412 KB |
Output is correct |
3 |
Correct |
40 ms |
9080 KB |
Output is correct |
4 |
Correct |
9 ms |
4096 KB |
Output is correct |
5 |
Correct |
8 ms |
3584 KB |
Output is correct |
6 |
Correct |
16 ms |
4992 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
40 ms |
6392 KB |
Output is correct |
9 |
Correct |
43 ms |
7804 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
69 ms |
9464 KB |
Output is correct |
12 |
Correct |
81 ms |
11000 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2816 KB |
Output is correct |
16 |
Correct |
4 ms |
2944 KB |
Output is correct |
17 |
Correct |
2 ms |
2688 KB |
Output is correct |
18 |
Correct |
3 ms |
2816 KB |
Output is correct |
19 |
Correct |
3 ms |
2816 KB |
Output is correct |
20 |
Correct |
2 ms |
2688 KB |
Output is correct |
21 |
Correct |
3 ms |
2816 KB |
Output is correct |
22 |
Correct |
3 ms |
2816 KB |
Output is correct |
23 |
Correct |
2 ms |
2688 KB |
Output is correct |
24 |
Correct |
2 ms |
2688 KB |
Output is correct |
25 |
Correct |
2 ms |
2688 KB |
Output is correct |
26 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
12408 KB |
Output is correct |
2 |
Correct |
59 ms |
12412 KB |
Output is correct |
3 |
Correct |
40 ms |
9080 KB |
Output is correct |
4 |
Correct |
9 ms |
4096 KB |
Output is correct |
5 |
Correct |
8 ms |
3584 KB |
Output is correct |
6 |
Correct |
16 ms |
4992 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
40 ms |
6392 KB |
Output is correct |
9 |
Correct |
43 ms |
7804 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
69 ms |
9464 KB |
Output is correct |
12 |
Correct |
81 ms |
11000 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
2 ms |
2688 KB |
Output is correct |
16 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |