# include "dreaming.h"
# include <iostream>
# include <vector>
# include <algorithm>
using namespace std;
const int NN = 1e5 + 100;
vector < pair < int, long long > > gr[NN];
vector < pair < long long, long long > > rads;
long long dist1[NN], dist2[NN], dia, rad, u;
bool used[NN];
void dfs( int v, int f, int c )
{
used[v] = true;
for ( auto to: gr[v] ){
if( to.first == f )
continue;
else{
long long dst = 0;
if( c == 1 ){
dist1[to.first] = dist1[v] + to.second;
dst = dist1[to.first];
}
else{
dist2[to.first] = dist2[v] + to.second;
dst = dist2[to.first];
}
if( dia < dst ){
dia = dst;
u = to.first;
}
dfs( to.first, v, c );
}
}
}
void jfs( int v, int f )
{
rad = min( rad, max( dist1[v], dist2[v] ) );
for ( auto to: gr[v] ){
if( to.first == f )
continue;
else{
jfs( to.first, v );
}
}
}
pair < long long, long long > get( int v )
{
dia = 0; u = 0;
dist1[v] = 0;
dfs( v, -1, 1 );
if( u == 0 )return {0, 0};
v = u; dia = 0;
dist1[v] = 0;
dfs( v, -1, 1 );
dist2[u] = 0;
dfs( u, -1, 2 );
rad = 1e18;
jfs( v, -1 );
return make_pair( rad, dia );
}
int travelTime( int N, int M, int L, int A[], int B[], int T[] )
{
for ( int i = 0; i < M; i ++ ){
gr[A[i]].push_back( { B[i], T[i] } );
gr[B[i]].push_back( { A[i], T[i] } );
}
for ( int i = 0; i < N; i ++ ){
if( used[i] ) continue;
rads.push_back( get( i ) );
}
sort( rads.begin(), rads.end() );
long long MaxDiameter = 0;
for ( auto rd: rads )
MaxDiameter = max( MaxDiameter, rd.second );
if( rads.size() == 1 )
return rads.back().second;
else if( rads.size() == 2 )
return max( MaxDiameter, rads[0].first + rads[1].first + L);
else
return max( MaxDiameter, max( rads[0].first + rads[1].first + L, rads[1].first + rads[2].first + L + L ) );
}
/*
int main()
{
int n, m, l;
cin >> n >> m >> l;
int a[NN] = {}, b[NN] = {}, t[NN] = {};
for ( int i = 0; i < m; i ++ ){
cin >> a[i] >> b[i] >> t[i];
}
cout << travelTime( n, m, l, a, b, t );
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
15472 KB |
Output is correct |
2 |
Correct |
108 ms |
15360 KB |
Output is correct |
3 |
Correct |
44 ms |
10872 KB |
Output is correct |
4 |
Correct |
12 ms |
4608 KB |
Output is correct |
5 |
Correct |
10 ms |
3840 KB |
Output is correct |
6 |
Correct |
20 ms |
5632 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
37 ms |
7544 KB |
Output is correct |
9 |
Correct |
43 ms |
9212 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
70 ms |
11384 KB |
Output is correct |
12 |
Correct |
103 ms |
13436 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
15472 KB |
Output is correct |
2 |
Correct |
108 ms |
15360 KB |
Output is correct |
3 |
Correct |
44 ms |
10872 KB |
Output is correct |
4 |
Correct |
12 ms |
4608 KB |
Output is correct |
5 |
Correct |
10 ms |
3840 KB |
Output is correct |
6 |
Correct |
20 ms |
5632 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
37 ms |
7544 KB |
Output is correct |
9 |
Correct |
43 ms |
9212 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
70 ms |
11384 KB |
Output is correct |
12 |
Correct |
103 ms |
13436 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2688 KB |
Output is correct |
16 |
Correct |
4 ms |
2688 KB |
Output is correct |
17 |
Correct |
4 ms |
2688 KB |
Output is correct |
18 |
Correct |
3 ms |
2788 KB |
Output is correct |
19 |
Correct |
4 ms |
2688 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
3 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2688 KB |
Output is correct |
24 |
Correct |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
4 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
4 ms |
2688 KB |
Output is correct |
28 |
Correct |
4 ms |
2688 KB |
Output is correct |
29 |
Correct |
4 ms |
2688 KB |
Output is correct |
30 |
Correct |
4 ms |
2688 KB |
Output is correct |
31 |
Correct |
4 ms |
2688 KB |
Output is correct |
32 |
Correct |
3 ms |
2688 KB |
Output is correct |
33 |
Correct |
4 ms |
2688 KB |
Output is correct |
34 |
Correct |
3 ms |
2688 KB |
Output is correct |
35 |
Correct |
3 ms |
2688 KB |
Output is correct |
36 |
Correct |
4 ms |
2688 KB |
Output is correct |
37 |
Correct |
4 ms |
2688 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
15472 KB |
Output is correct |
2 |
Correct |
108 ms |
15360 KB |
Output is correct |
3 |
Correct |
44 ms |
10872 KB |
Output is correct |
4 |
Correct |
12 ms |
4608 KB |
Output is correct |
5 |
Correct |
10 ms |
3840 KB |
Output is correct |
6 |
Correct |
20 ms |
5632 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
37 ms |
7544 KB |
Output is correct |
9 |
Correct |
43 ms |
9212 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
70 ms |
11384 KB |
Output is correct |
12 |
Correct |
103 ms |
13436 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2688 KB |
Output is correct |
16 |
Correct |
4 ms |
2688 KB |
Output is correct |
17 |
Correct |
4 ms |
2688 KB |
Output is correct |
18 |
Correct |
3 ms |
2788 KB |
Output is correct |
19 |
Correct |
4 ms |
2688 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
3 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2688 KB |
Output is correct |
24 |
Correct |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
4 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
4 ms |
2688 KB |
Output is correct |
28 |
Correct |
4 ms |
2688 KB |
Output is correct |
29 |
Correct |
4 ms |
2688 KB |
Output is correct |
30 |
Correct |
4 ms |
2688 KB |
Output is correct |
31 |
Correct |
4 ms |
2688 KB |
Output is correct |
32 |
Correct |
3 ms |
2688 KB |
Output is correct |
33 |
Correct |
4 ms |
2688 KB |
Output is correct |
34 |
Correct |
3 ms |
2688 KB |
Output is correct |
35 |
Correct |
3 ms |
2688 KB |
Output is correct |
36 |
Correct |
4 ms |
2688 KB |
Output is correct |
37 |
Correct |
4 ms |
2688 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
39 |
Correct |
105 ms |
15224 KB |
Output is correct |
40 |
Correct |
89 ms |
15312 KB |
Output is correct |
41 |
Correct |
48 ms |
11000 KB |
Output is correct |
42 |
Correct |
12 ms |
4608 KB |
Output is correct |
43 |
Correct |
4 ms |
2688 KB |
Output is correct |
44 |
Correct |
4 ms |
2688 KB |
Output is correct |
45 |
Correct |
4 ms |
2688 KB |
Output is correct |
46 |
Correct |
4 ms |
2688 KB |
Output is correct |
47 |
Correct |
4 ms |
2688 KB |
Output is correct |
48 |
Correct |
11 ms |
2688 KB |
Output is correct |
49 |
Correct |
4 ms |
2688 KB |
Output is correct |
50 |
Correct |
5 ms |
2816 KB |
Output is correct |
51 |
Correct |
4 ms |
2688 KB |
Output is correct |
52 |
Correct |
4 ms |
2688 KB |
Output is correct |
53 |
Correct |
4 ms |
2660 KB |
Output is correct |
54 |
Correct |
4 ms |
2688 KB |
Output is correct |
55 |
Correct |
4 ms |
2688 KB |
Output is correct |
56 |
Correct |
4 ms |
2688 KB |
Output is correct |
57 |
Correct |
102 ms |
11512 KB |
Output is correct |
58 |
Correct |
96 ms |
11512 KB |
Output is correct |
59 |
Correct |
128 ms |
11164 KB |
Output is correct |
60 |
Correct |
110 ms |
11264 KB |
Output is correct |
61 |
Correct |
107 ms |
11004 KB |
Output is correct |
62 |
Correct |
94 ms |
11000 KB |
Output is correct |
63 |
Correct |
94 ms |
10616 KB |
Output is correct |
64 |
Correct |
92 ms |
10620 KB |
Output is correct |
65 |
Correct |
81 ms |
10748 KB |
Output is correct |
66 |
Correct |
91 ms |
10616 KB |
Output is correct |
67 |
Correct |
113 ms |
11140 KB |
Output is correct |
68 |
Correct |
104 ms |
11128 KB |
Output is correct |
69 |
Correct |
129 ms |
11128 KB |
Output is correct |
70 |
Correct |
140 ms |
11132 KB |
Output is correct |
71 |
Correct |
4 ms |
2688 KB |
Output is correct |
72 |
Correct |
6 ms |
2944 KB |
Output is correct |
73 |
Correct |
5 ms |
2944 KB |
Output is correct |
74 |
Correct |
5 ms |
2944 KB |
Output is correct |
75 |
Correct |
5 ms |
2944 KB |
Output is correct |
76 |
Correct |
6 ms |
2988 KB |
Output is correct |
77 |
Correct |
5 ms |
2944 KB |
Output is correct |
78 |
Correct |
5 ms |
2944 KB |
Output is correct |
79 |
Correct |
6 ms |
2944 KB |
Output is correct |
80 |
Correct |
125 ms |
11264 KB |
Output is correct |
81 |
Correct |
110 ms |
11200 KB |
Output is correct |
82 |
Correct |
118 ms |
10964 KB |
Output is correct |
83 |
Correct |
101 ms |
10916 KB |
Output is correct |
84 |
Correct |
5 ms |
2944 KB |
Output is correct |
85 |
Correct |
5 ms |
2816 KB |
Output is correct |
86 |
Correct |
5 ms |
2944 KB |
Output is correct |
87 |
Correct |
6 ms |
2944 KB |
Output is correct |
88 |
Correct |
5 ms |
2944 KB |
Output is correct |
89 |
Correct |
5 ms |
2944 KB |
Output is correct |
90 |
Correct |
5 ms |
2944 KB |
Output is correct |
91 |
Correct |
6 ms |
2944 KB |
Output is correct |
92 |
Correct |
5 ms |
2944 KB |
Output is correct |
93 |
Correct |
5 ms |
2944 KB |
Output is correct |
94 |
Correct |
4 ms |
2660 KB |
Output is correct |
95 |
Correct |
4 ms |
2688 KB |
Output is correct |
96 |
Correct |
4 ms |
2688 KB |
Output is correct |
97 |
Correct |
4 ms |
2688 KB |
Output is correct |
98 |
Correct |
4 ms |
2688 KB |
Output is correct |
99 |
Correct |
4 ms |
2688 KB |
Output is correct |
100 |
Correct |
4 ms |
2688 KB |
Output is correct |
101 |
Correct |
4 ms |
2688 KB |
Output is correct |
102 |
Correct |
4 ms |
2688 KB |
Output is correct |
103 |
Correct |
3 ms |
2688 KB |
Output is correct |
104 |
Correct |
11 ms |
3840 KB |
Output is correct |
105 |
Correct |
19 ms |
5632 KB |
Output is correct |
106 |
Correct |
4 ms |
2816 KB |
Output is correct |
107 |
Correct |
36 ms |
7416 KB |
Output is correct |
108 |
Correct |
55 ms |
9336 KB |
Output is correct |
109 |
Correct |
4 ms |
2816 KB |
Output is correct |
110 |
Correct |
69 ms |
11336 KB |
Output is correct |
111 |
Correct |
99 ms |
13432 KB |
Output is correct |
112 |
Correct |
4 ms |
2944 KB |
Output is correct |
113 |
Correct |
140 ms |
17016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
31 ms |
7796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
15472 KB |
Output is correct |
2 |
Correct |
108 ms |
15360 KB |
Output is correct |
3 |
Correct |
44 ms |
10872 KB |
Output is correct |
4 |
Correct |
12 ms |
4608 KB |
Output is correct |
5 |
Correct |
10 ms |
3840 KB |
Output is correct |
6 |
Correct |
20 ms |
5632 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
37 ms |
7544 KB |
Output is correct |
9 |
Correct |
43 ms |
9212 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
70 ms |
11384 KB |
Output is correct |
12 |
Correct |
103 ms |
13436 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
4 ms |
2816 KB |
Output is correct |
15 |
Correct |
5 ms |
2816 KB |
Output is correct |
16 |
Correct |
5 ms |
3072 KB |
Output is correct |
17 |
Incorrect |
4 ms |
2816 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
15472 KB |
Output is correct |
2 |
Correct |
108 ms |
15360 KB |
Output is correct |
3 |
Correct |
44 ms |
10872 KB |
Output is correct |
4 |
Correct |
12 ms |
4608 KB |
Output is correct |
5 |
Correct |
10 ms |
3840 KB |
Output is correct |
6 |
Correct |
20 ms |
5632 KB |
Output is correct |
7 |
Correct |
4 ms |
2688 KB |
Output is correct |
8 |
Correct |
37 ms |
7544 KB |
Output is correct |
9 |
Correct |
43 ms |
9212 KB |
Output is correct |
10 |
Correct |
4 ms |
2816 KB |
Output is correct |
11 |
Correct |
70 ms |
11384 KB |
Output is correct |
12 |
Correct |
103 ms |
13436 KB |
Output is correct |
13 |
Correct |
4 ms |
2816 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2688 KB |
Output is correct |
16 |
Correct |
4 ms |
2688 KB |
Output is correct |
17 |
Correct |
4 ms |
2688 KB |
Output is correct |
18 |
Correct |
3 ms |
2788 KB |
Output is correct |
19 |
Correct |
4 ms |
2688 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
21 |
Correct |
4 ms |
2688 KB |
Output is correct |
22 |
Correct |
3 ms |
2688 KB |
Output is correct |
23 |
Correct |
4 ms |
2688 KB |
Output is correct |
24 |
Correct |
4 ms |
2688 KB |
Output is correct |
25 |
Correct |
4 ms |
2688 KB |
Output is correct |
26 |
Correct |
4 ms |
2688 KB |
Output is correct |
27 |
Correct |
4 ms |
2688 KB |
Output is correct |
28 |
Correct |
4 ms |
2688 KB |
Output is correct |
29 |
Correct |
4 ms |
2688 KB |
Output is correct |
30 |
Correct |
4 ms |
2688 KB |
Output is correct |
31 |
Correct |
4 ms |
2688 KB |
Output is correct |
32 |
Correct |
3 ms |
2688 KB |
Output is correct |
33 |
Correct |
4 ms |
2688 KB |
Output is correct |
34 |
Correct |
3 ms |
2688 KB |
Output is correct |
35 |
Correct |
3 ms |
2688 KB |
Output is correct |
36 |
Correct |
4 ms |
2688 KB |
Output is correct |
37 |
Correct |
4 ms |
2688 KB |
Output is correct |
38 |
Correct |
4 ms |
2688 KB |
Output is correct |
39 |
Correct |
105 ms |
15224 KB |
Output is correct |
40 |
Correct |
89 ms |
15312 KB |
Output is correct |
41 |
Correct |
48 ms |
11000 KB |
Output is correct |
42 |
Correct |
12 ms |
4608 KB |
Output is correct |
43 |
Correct |
4 ms |
2688 KB |
Output is correct |
44 |
Correct |
4 ms |
2688 KB |
Output is correct |
45 |
Correct |
4 ms |
2688 KB |
Output is correct |
46 |
Correct |
4 ms |
2688 KB |
Output is correct |
47 |
Correct |
4 ms |
2688 KB |
Output is correct |
48 |
Correct |
11 ms |
2688 KB |
Output is correct |
49 |
Correct |
4 ms |
2688 KB |
Output is correct |
50 |
Correct |
5 ms |
2816 KB |
Output is correct |
51 |
Correct |
4 ms |
2688 KB |
Output is correct |
52 |
Correct |
4 ms |
2688 KB |
Output is correct |
53 |
Correct |
4 ms |
2660 KB |
Output is correct |
54 |
Correct |
4 ms |
2688 KB |
Output is correct |
55 |
Correct |
4 ms |
2688 KB |
Output is correct |
56 |
Correct |
4 ms |
2688 KB |
Output is correct |
57 |
Correct |
102 ms |
11512 KB |
Output is correct |
58 |
Correct |
96 ms |
11512 KB |
Output is correct |
59 |
Correct |
128 ms |
11164 KB |
Output is correct |
60 |
Correct |
110 ms |
11264 KB |
Output is correct |
61 |
Correct |
107 ms |
11004 KB |
Output is correct |
62 |
Correct |
94 ms |
11000 KB |
Output is correct |
63 |
Correct |
94 ms |
10616 KB |
Output is correct |
64 |
Correct |
92 ms |
10620 KB |
Output is correct |
65 |
Correct |
81 ms |
10748 KB |
Output is correct |
66 |
Correct |
91 ms |
10616 KB |
Output is correct |
67 |
Correct |
113 ms |
11140 KB |
Output is correct |
68 |
Correct |
104 ms |
11128 KB |
Output is correct |
69 |
Correct |
129 ms |
11128 KB |
Output is correct |
70 |
Correct |
140 ms |
11132 KB |
Output is correct |
71 |
Correct |
4 ms |
2688 KB |
Output is correct |
72 |
Correct |
6 ms |
2944 KB |
Output is correct |
73 |
Correct |
5 ms |
2944 KB |
Output is correct |
74 |
Correct |
5 ms |
2944 KB |
Output is correct |
75 |
Correct |
5 ms |
2944 KB |
Output is correct |
76 |
Correct |
6 ms |
2988 KB |
Output is correct |
77 |
Correct |
5 ms |
2944 KB |
Output is correct |
78 |
Correct |
5 ms |
2944 KB |
Output is correct |
79 |
Correct |
6 ms |
2944 KB |
Output is correct |
80 |
Correct |
125 ms |
11264 KB |
Output is correct |
81 |
Correct |
110 ms |
11200 KB |
Output is correct |
82 |
Correct |
118 ms |
10964 KB |
Output is correct |
83 |
Correct |
101 ms |
10916 KB |
Output is correct |
84 |
Correct |
5 ms |
2944 KB |
Output is correct |
85 |
Correct |
5 ms |
2816 KB |
Output is correct |
86 |
Correct |
5 ms |
2944 KB |
Output is correct |
87 |
Correct |
6 ms |
2944 KB |
Output is correct |
88 |
Correct |
5 ms |
2944 KB |
Output is correct |
89 |
Correct |
5 ms |
2944 KB |
Output is correct |
90 |
Correct |
5 ms |
2944 KB |
Output is correct |
91 |
Correct |
6 ms |
2944 KB |
Output is correct |
92 |
Correct |
5 ms |
2944 KB |
Output is correct |
93 |
Correct |
5 ms |
2944 KB |
Output is correct |
94 |
Correct |
4 ms |
2660 KB |
Output is correct |
95 |
Correct |
4 ms |
2688 KB |
Output is correct |
96 |
Correct |
4 ms |
2688 KB |
Output is correct |
97 |
Correct |
4 ms |
2688 KB |
Output is correct |
98 |
Correct |
4 ms |
2688 KB |
Output is correct |
99 |
Correct |
4 ms |
2688 KB |
Output is correct |
100 |
Correct |
4 ms |
2688 KB |
Output is correct |
101 |
Correct |
4 ms |
2688 KB |
Output is correct |
102 |
Correct |
4 ms |
2688 KB |
Output is correct |
103 |
Correct |
3 ms |
2688 KB |
Output is correct |
104 |
Correct |
11 ms |
3840 KB |
Output is correct |
105 |
Correct |
19 ms |
5632 KB |
Output is correct |
106 |
Correct |
4 ms |
2816 KB |
Output is correct |
107 |
Correct |
36 ms |
7416 KB |
Output is correct |
108 |
Correct |
55 ms |
9336 KB |
Output is correct |
109 |
Correct |
4 ms |
2816 KB |
Output is correct |
110 |
Correct |
69 ms |
11336 KB |
Output is correct |
111 |
Correct |
99 ms |
13432 KB |
Output is correct |
112 |
Correct |
4 ms |
2944 KB |
Output is correct |
113 |
Correct |
140 ms |
17016 KB |
Output is correct |
114 |
Incorrect |
31 ms |
7796 KB |
Output isn't correct |
115 |
Halted |
0 ms |
0 KB |
- |