#include "dreaming.h"
#include <vector>
#include <stdio.h>
using namespace std;
vector < pair < int , int > > Next[100005];
bool have[100005]={0};
int a=0,b=0,c=0,t=0,big=0,bb=0,where;
void F(int here,int 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(int here,int Father,int 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(int here,int Father,int 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[])
{
int i,how=0;
for(i=0;i<M;i++)
{
Next[A[i]].push_back(make_pair(B[i],T[i]));
Next[B[i]].push_back(make_pair(A[i],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;
}
}
if(how>=2) bb=max(bb,a+b+L);
if(how>=3)
{
while(1) ;
bb=max(bb,b+c+2*L);
}
return bb;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
11000 KB |
Output is correct |
2 |
Correct |
59 ms |
10872 KB |
Output is correct |
3 |
Correct |
38 ms |
8056 KB |
Output is correct |
4 |
Correct |
9 ms |
3840 KB |
Output is correct |
5 |
Correct |
8 ms |
3328 KB |
Output is correct |
6 |
Correct |
16 ms |
4456 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
29 ms |
5632 KB |
Output is correct |
9 |
Correct |
36 ms |
6784 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
61 ms |
8060 KB |
Output is correct |
12 |
Correct |
70 ms |
9464 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
11000 KB |
Output is correct |
2 |
Correct |
59 ms |
10872 KB |
Output is correct |
3 |
Correct |
38 ms |
8056 KB |
Output is correct |
4 |
Correct |
9 ms |
3840 KB |
Output is correct |
5 |
Correct |
8 ms |
3328 KB |
Output is correct |
6 |
Correct |
16 ms |
4456 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
29 ms |
5632 KB |
Output is correct |
9 |
Correct |
36 ms |
6784 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
61 ms |
8060 KB |
Output is correct |
12 |
Correct |
70 ms |
9464 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
11000 KB |
Output is correct |
2 |
Correct |
59 ms |
10872 KB |
Output is correct |
3 |
Correct |
38 ms |
8056 KB |
Output is correct |
4 |
Correct |
9 ms |
3840 KB |
Output is correct |
5 |
Correct |
8 ms |
3328 KB |
Output is correct |
6 |
Correct |
16 ms |
4456 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
29 ms |
5632 KB |
Output is correct |
9 |
Correct |
36 ms |
6784 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
61 ms |
8060 KB |
Output is correct |
12 |
Correct |
70 ms |
9464 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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
5120 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
11000 KB |
Output is correct |
2 |
Correct |
59 ms |
10872 KB |
Output is correct |
3 |
Correct |
38 ms |
8056 KB |
Output is correct |
4 |
Correct |
9 ms |
3840 KB |
Output is correct |
5 |
Correct |
8 ms |
3328 KB |
Output is correct |
6 |
Correct |
16 ms |
4456 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
29 ms |
5632 KB |
Output is correct |
9 |
Correct |
36 ms |
6784 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
61 ms |
8060 KB |
Output is correct |
12 |
Correct |
70 ms |
9464 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
14 |
Execution timed out |
1085 ms |
2688 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
11000 KB |
Output is correct |
2 |
Correct |
59 ms |
10872 KB |
Output is correct |
3 |
Correct |
38 ms |
8056 KB |
Output is correct |
4 |
Correct |
9 ms |
3840 KB |
Output is correct |
5 |
Correct |
8 ms |
3328 KB |
Output is correct |
6 |
Correct |
16 ms |
4456 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
29 ms |
5632 KB |
Output is correct |
9 |
Correct |
36 ms |
6784 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
61 ms |
8060 KB |
Output is correct |
12 |
Correct |
70 ms |
9464 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 |
- |