#include "dreaming.h"
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
const ll inf = 1e18 + 10000;
const int mod = 1e9+7;
const int maxn = 2e6 + 12;
vt<pii> g[maxn];
ll mx[maxn][2], ret, rad;
bool was[maxn];
void dfs(int v){
was[v] = 1;
for(auto i : g[v]){
if(!was[i.ff]){
dfs(i.ff);
int x = mx[i.ff][0] + i.ss;
if(mx[v][0] < x)mx[v][1] = mx[v][0], mx[v][0] = x;
else if(mx[v][1] < x)mx[v][1] = x;
}
}
}
void rlx(int v, ll x, int pr){
for(auto i : g[v]){
if(i.ff != pr){
if(mx[v][0] == i.ss + mx[i.ff][0])rlx(i.ff, max(x, mx[v][1]) + i.ss, v);
else rlx(i.ff, max(x, mx[v][0]) + i.ss, v);
}
}
if(x > mx[v][0])mx[v][1] = mx[v][0], mx[v][0] = x;
else if(x > mx[v][1])mx[v][1] = x;
ret = max(ret, mx[v][0] + mx[v][1]);
rad = min(rad, mx[v][0]);
}
int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
for(int i = 0; i < m; i++){
g[a[i]].pb({b[i], t[i]});
g[b[i]].pb({a[i], t[i]});
}
vt<ll> sr;
for(int i = 0; i < n; i++){
if(!was[i]){
dfs(i);
rad = mx[i][0];
rlx(i, 0, 0);
sr.pb(rad);
}
}
sort(all(sr));
if(sr.size() > 1)ret = max(ret, l + sr.back() + sr[sr.size() - 2]);
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
61080 KB |
Output is correct |
2 |
Correct |
51 ms |
60732 KB |
Output is correct |
3 |
Correct |
34 ms |
59476 KB |
Output is correct |
4 |
Correct |
15 ms |
52316 KB |
Output is correct |
5 |
Correct |
14 ms |
51548 KB |
Output is correct |
6 |
Correct |
19 ms |
53084 KB |
Output is correct |
7 |
Correct |
12 ms |
50888 KB |
Output is correct |
8 |
Correct |
27 ms |
55124 KB |
Output is correct |
9 |
Correct |
32 ms |
57692 KB |
Output is correct |
10 |
Correct |
11 ms |
50988 KB |
Output is correct |
11 |
Correct |
41 ms |
58452 KB |
Output is correct |
12 |
Correct |
44 ms |
59728 KB |
Output is correct |
13 |
Correct |
11 ms |
50780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
50780 KB |
Output is correct |
2 |
Correct |
11 ms |
50780 KB |
Output is correct |
3 |
Correct |
10 ms |
50780 KB |
Output is correct |
4 |
Correct |
11 ms |
50916 KB |
Output is correct |
5 |
Correct |
11 ms |
50780 KB |
Output is correct |
6 |
Correct |
11 ms |
50904 KB |
Output is correct |
7 |
Correct |
11 ms |
50780 KB |
Output is correct |
8 |
Correct |
11 ms |
50908 KB |
Output is correct |
9 |
Correct |
12 ms |
50780 KB |
Output is correct |
10 |
Correct |
11 ms |
50780 KB |
Output is correct |
11 |
Correct |
11 ms |
50780 KB |
Output is correct |
12 |
Correct |
11 ms |
50668 KB |
Output is correct |
13 |
Correct |
10 ms |
50776 KB |
Output is correct |
14 |
Correct |
11 ms |
50884 KB |
Output is correct |
15 |
Correct |
10 ms |
48732 KB |
Output is correct |
16 |
Correct |
12 ms |
50780 KB |
Output is correct |
17 |
Correct |
11 ms |
51032 KB |
Output is correct |
18 |
Correct |
11 ms |
50780 KB |
Output is correct |
19 |
Correct |
10 ms |
50776 KB |
Output is correct |
20 |
Correct |
10 ms |
50980 KB |
Output is correct |
21 |
Correct |
11 ms |
50780 KB |
Output is correct |
22 |
Correct |
11 ms |
50776 KB |
Output is correct |
23 |
Correct |
11 ms |
50776 KB |
Output is correct |
24 |
Correct |
10 ms |
50664 KB |
Output is correct |
25 |
Correct |
11 ms |
50908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
61080 KB |
Output is correct |
2 |
Correct |
51 ms |
60732 KB |
Output is correct |
3 |
Correct |
34 ms |
59476 KB |
Output is correct |
4 |
Correct |
15 ms |
52316 KB |
Output is correct |
5 |
Correct |
14 ms |
51548 KB |
Output is correct |
6 |
Correct |
19 ms |
53084 KB |
Output is correct |
7 |
Correct |
12 ms |
50888 KB |
Output is correct |
8 |
Correct |
27 ms |
55124 KB |
Output is correct |
9 |
Correct |
32 ms |
57692 KB |
Output is correct |
10 |
Correct |
11 ms |
50988 KB |
Output is correct |
11 |
Correct |
41 ms |
58452 KB |
Output is correct |
12 |
Correct |
44 ms |
59728 KB |
Output is correct |
13 |
Correct |
11 ms |
50780 KB |
Output is correct |
14 |
Correct |
10 ms |
50780 KB |
Output is correct |
15 |
Correct |
11 ms |
50780 KB |
Output is correct |
16 |
Correct |
10 ms |
50780 KB |
Output is correct |
17 |
Correct |
11 ms |
50916 KB |
Output is correct |
18 |
Correct |
11 ms |
50780 KB |
Output is correct |
19 |
Correct |
11 ms |
50904 KB |
Output is correct |
20 |
Correct |
11 ms |
50780 KB |
Output is correct |
21 |
Correct |
11 ms |
50908 KB |
Output is correct |
22 |
Correct |
12 ms |
50780 KB |
Output is correct |
23 |
Correct |
11 ms |
50780 KB |
Output is correct |
24 |
Correct |
11 ms |
50780 KB |
Output is correct |
25 |
Correct |
11 ms |
50668 KB |
Output is correct |
26 |
Correct |
10 ms |
50776 KB |
Output is correct |
27 |
Correct |
11 ms |
50884 KB |
Output is correct |
28 |
Correct |
10 ms |
48732 KB |
Output is correct |
29 |
Correct |
12 ms |
50780 KB |
Output is correct |
30 |
Correct |
11 ms |
51032 KB |
Output is correct |
31 |
Correct |
11 ms |
50780 KB |
Output is correct |
32 |
Correct |
10 ms |
50776 KB |
Output is correct |
33 |
Correct |
10 ms |
50980 KB |
Output is correct |
34 |
Correct |
11 ms |
50780 KB |
Output is correct |
35 |
Correct |
11 ms |
50776 KB |
Output is correct |
36 |
Correct |
11 ms |
50776 KB |
Output is correct |
37 |
Correct |
10 ms |
50664 KB |
Output is correct |
38 |
Correct |
11 ms |
50908 KB |
Output is correct |
39 |
Correct |
43 ms |
61276 KB |
Output is correct |
40 |
Correct |
44 ms |
60764 KB |
Output is correct |
41 |
Correct |
34 ms |
59480 KB |
Output is correct |
42 |
Correct |
16 ms |
52316 KB |
Output is correct |
43 |
Correct |
11 ms |
50892 KB |
Output is correct |
44 |
Correct |
11 ms |
50780 KB |
Output is correct |
45 |
Correct |
11 ms |
50780 KB |
Output is correct |
46 |
Correct |
12 ms |
50780 KB |
Output is correct |
47 |
Correct |
11 ms |
50780 KB |
Output is correct |
48 |
Correct |
11 ms |
50916 KB |
Output is correct |
49 |
Correct |
11 ms |
50780 KB |
Output is correct |
50 |
Correct |
11 ms |
50776 KB |
Output is correct |
51 |
Correct |
11 ms |
50780 KB |
Output is correct |
52 |
Correct |
10 ms |
50780 KB |
Output is correct |
53 |
Correct |
10 ms |
50884 KB |
Output is correct |
54 |
Correct |
11 ms |
50912 KB |
Output is correct |
55 |
Correct |
11 ms |
50780 KB |
Output is correct |
56 |
Correct |
11 ms |
50888 KB |
Output is correct |
57 |
Correct |
47 ms |
57940 KB |
Output is correct |
58 |
Correct |
49 ms |
57940 KB |
Output is correct |
59 |
Correct |
53 ms |
57816 KB |
Output is correct |
60 |
Correct |
49 ms |
57680 KB |
Output is correct |
61 |
Correct |
48 ms |
58100 KB |
Output is correct |
62 |
Correct |
51 ms |
57960 KB |
Output is correct |
63 |
Correct |
46 ms |
57436 KB |
Output is correct |
64 |
Correct |
47 ms |
57424 KB |
Output is correct |
65 |
Correct |
48 ms |
57828 KB |
Output is correct |
66 |
Correct |
48 ms |
57848 KB |
Output is correct |
67 |
Correct |
49 ms |
57888 KB |
Output is correct |
68 |
Correct |
48 ms |
57884 KB |
Output is correct |
69 |
Correct |
51 ms |
58192 KB |
Output is correct |
70 |
Correct |
50 ms |
57936 KB |
Output is correct |
71 |
Correct |
11 ms |
48844 KB |
Output is correct |
72 |
Correct |
13 ms |
50924 KB |
Output is correct |
73 |
Correct |
12 ms |
51036 KB |
Output is correct |
74 |
Correct |
12 ms |
51120 KB |
Output is correct |
75 |
Correct |
11 ms |
51036 KB |
Output is correct |
76 |
Correct |
11 ms |
51036 KB |
Output is correct |
77 |
Correct |
12 ms |
51036 KB |
Output is correct |
78 |
Correct |
12 ms |
50884 KB |
Output is correct |
79 |
Correct |
12 ms |
50916 KB |
Output is correct |
80 |
Correct |
49 ms |
57892 KB |
Output is correct |
81 |
Correct |
56 ms |
57676 KB |
Output is correct |
82 |
Correct |
49 ms |
57936 KB |
Output is correct |
83 |
Correct |
48 ms |
57936 KB |
Output is correct |
84 |
Correct |
11 ms |
51032 KB |
Output is correct |
85 |
Correct |
11 ms |
51036 KB |
Output is correct |
86 |
Correct |
11 ms |
51036 KB |
Output is correct |
87 |
Correct |
11 ms |
51288 KB |
Output is correct |
88 |
Correct |
11 ms |
50924 KB |
Output is correct |
89 |
Correct |
11 ms |
51036 KB |
Output is correct |
90 |
Correct |
11 ms |
51036 KB |
Output is correct |
91 |
Correct |
12 ms |
51036 KB |
Output is correct |
92 |
Correct |
13 ms |
51036 KB |
Output is correct |
93 |
Correct |
11 ms |
51036 KB |
Output is correct |
94 |
Correct |
11 ms |
50780 KB |
Output is correct |
95 |
Correct |
11 ms |
50780 KB |
Output is correct |
96 |
Correct |
11 ms |
50660 KB |
Output is correct |
97 |
Correct |
10 ms |
50680 KB |
Output is correct |
98 |
Correct |
10 ms |
50780 KB |
Output is correct |
99 |
Correct |
11 ms |
50888 KB |
Output is correct |
100 |
Correct |
10 ms |
50780 KB |
Output is correct |
101 |
Correct |
11 ms |
50668 KB |
Output is correct |
102 |
Correct |
11 ms |
50780 KB |
Output is correct |
103 |
Correct |
11 ms |
50780 KB |
Output is correct |
104 |
Correct |
14 ms |
51548 KB |
Output is correct |
105 |
Correct |
19 ms |
53072 KB |
Output is correct |
106 |
Correct |
12 ms |
50776 KB |
Output is correct |
107 |
Correct |
26 ms |
55132 KB |
Output is correct |
108 |
Correct |
33 ms |
57504 KB |
Output is correct |
109 |
Correct |
11 ms |
50780 KB |
Output is correct |
110 |
Correct |
40 ms |
58336 KB |
Output is correct |
111 |
Correct |
43 ms |
59728 KB |
Output is correct |
112 |
Correct |
11 ms |
50780 KB |
Output is correct |
113 |
Correct |
60 ms |
65536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
55520 KB |
Output is correct |
2 |
Incorrect |
26 ms |
55516 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
50780 KB |
Output is correct |
2 |
Correct |
11 ms |
50780 KB |
Output is correct |
3 |
Correct |
10 ms |
50780 KB |
Output is correct |
4 |
Correct |
11 ms |
50916 KB |
Output is correct |
5 |
Correct |
11 ms |
50780 KB |
Output is correct |
6 |
Correct |
11 ms |
50904 KB |
Output is correct |
7 |
Correct |
11 ms |
50780 KB |
Output is correct |
8 |
Correct |
11 ms |
50908 KB |
Output is correct |
9 |
Correct |
12 ms |
50780 KB |
Output is correct |
10 |
Correct |
11 ms |
50780 KB |
Output is correct |
11 |
Correct |
11 ms |
50780 KB |
Output is correct |
12 |
Correct |
11 ms |
50668 KB |
Output is correct |
13 |
Correct |
10 ms |
50776 KB |
Output is correct |
14 |
Correct |
11 ms |
50884 KB |
Output is correct |
15 |
Correct |
10 ms |
48732 KB |
Output is correct |
16 |
Correct |
12 ms |
50780 KB |
Output is correct |
17 |
Correct |
11 ms |
51032 KB |
Output is correct |
18 |
Correct |
11 ms |
50780 KB |
Output is correct |
19 |
Correct |
10 ms |
50776 KB |
Output is correct |
20 |
Correct |
10 ms |
50980 KB |
Output is correct |
21 |
Correct |
11 ms |
50780 KB |
Output is correct |
22 |
Correct |
11 ms |
50776 KB |
Output is correct |
23 |
Correct |
11 ms |
50776 KB |
Output is correct |
24 |
Correct |
10 ms |
50664 KB |
Output is correct |
25 |
Correct |
11 ms |
50908 KB |
Output is correct |
26 |
Correct |
11 ms |
50780 KB |
Output is correct |
27 |
Correct |
11 ms |
50900 KB |
Output is correct |
28 |
Correct |
12 ms |
50944 KB |
Output is correct |
29 |
Correct |
11 ms |
50780 KB |
Output is correct |
30 |
Correct |
12 ms |
51032 KB |
Output is correct |
31 |
Correct |
12 ms |
51036 KB |
Output is correct |
32 |
Incorrect |
12 ms |
50780 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
61080 KB |
Output is correct |
2 |
Correct |
51 ms |
60732 KB |
Output is correct |
3 |
Correct |
34 ms |
59476 KB |
Output is correct |
4 |
Correct |
15 ms |
52316 KB |
Output is correct |
5 |
Correct |
14 ms |
51548 KB |
Output is correct |
6 |
Correct |
19 ms |
53084 KB |
Output is correct |
7 |
Correct |
12 ms |
50888 KB |
Output is correct |
8 |
Correct |
27 ms |
55124 KB |
Output is correct |
9 |
Correct |
32 ms |
57692 KB |
Output is correct |
10 |
Correct |
11 ms |
50988 KB |
Output is correct |
11 |
Correct |
41 ms |
58452 KB |
Output is correct |
12 |
Correct |
44 ms |
59728 KB |
Output is correct |
13 |
Correct |
11 ms |
50780 KB |
Output is correct |
14 |
Correct |
10 ms |
50780 KB |
Output is correct |
15 |
Correct |
11 ms |
50780 KB |
Output is correct |
16 |
Correct |
10 ms |
50780 KB |
Output is correct |
17 |
Correct |
11 ms |
50916 KB |
Output is correct |
18 |
Correct |
11 ms |
50780 KB |
Output is correct |
19 |
Correct |
11 ms |
50904 KB |
Output is correct |
20 |
Correct |
11 ms |
50780 KB |
Output is correct |
21 |
Correct |
11 ms |
50908 KB |
Output is correct |
22 |
Correct |
12 ms |
50780 KB |
Output is correct |
23 |
Correct |
11 ms |
50780 KB |
Output is correct |
24 |
Correct |
11 ms |
50780 KB |
Output is correct |
25 |
Correct |
11 ms |
50668 KB |
Output is correct |
26 |
Correct |
10 ms |
50776 KB |
Output is correct |
27 |
Correct |
11 ms |
50884 KB |
Output is correct |
28 |
Correct |
10 ms |
48732 KB |
Output is correct |
29 |
Correct |
12 ms |
50780 KB |
Output is correct |
30 |
Correct |
11 ms |
51032 KB |
Output is correct |
31 |
Correct |
11 ms |
50780 KB |
Output is correct |
32 |
Correct |
10 ms |
50776 KB |
Output is correct |
33 |
Correct |
10 ms |
50980 KB |
Output is correct |
34 |
Correct |
11 ms |
50780 KB |
Output is correct |
35 |
Correct |
11 ms |
50776 KB |
Output is correct |
36 |
Correct |
11 ms |
50776 KB |
Output is correct |
37 |
Correct |
10 ms |
50664 KB |
Output is correct |
38 |
Correct |
11 ms |
50908 KB |
Output is correct |
39 |
Correct |
43 ms |
61276 KB |
Output is correct |
40 |
Correct |
44 ms |
60764 KB |
Output is correct |
41 |
Correct |
34 ms |
59480 KB |
Output is correct |
42 |
Correct |
16 ms |
52316 KB |
Output is correct |
43 |
Correct |
11 ms |
50892 KB |
Output is correct |
44 |
Correct |
11 ms |
50780 KB |
Output is correct |
45 |
Correct |
11 ms |
50780 KB |
Output is correct |
46 |
Correct |
12 ms |
50780 KB |
Output is correct |
47 |
Correct |
11 ms |
50780 KB |
Output is correct |
48 |
Correct |
11 ms |
50916 KB |
Output is correct |
49 |
Correct |
11 ms |
50780 KB |
Output is correct |
50 |
Correct |
11 ms |
50776 KB |
Output is correct |
51 |
Correct |
11 ms |
50780 KB |
Output is correct |
52 |
Correct |
10 ms |
50780 KB |
Output is correct |
53 |
Correct |
10 ms |
50884 KB |
Output is correct |
54 |
Correct |
11 ms |
50912 KB |
Output is correct |
55 |
Correct |
11 ms |
50780 KB |
Output is correct |
56 |
Correct |
11 ms |
50888 KB |
Output is correct |
57 |
Correct |
47 ms |
57940 KB |
Output is correct |
58 |
Correct |
49 ms |
57940 KB |
Output is correct |
59 |
Correct |
53 ms |
57816 KB |
Output is correct |
60 |
Correct |
49 ms |
57680 KB |
Output is correct |
61 |
Correct |
48 ms |
58100 KB |
Output is correct |
62 |
Correct |
51 ms |
57960 KB |
Output is correct |
63 |
Correct |
46 ms |
57436 KB |
Output is correct |
64 |
Correct |
47 ms |
57424 KB |
Output is correct |
65 |
Correct |
48 ms |
57828 KB |
Output is correct |
66 |
Correct |
48 ms |
57848 KB |
Output is correct |
67 |
Correct |
49 ms |
57888 KB |
Output is correct |
68 |
Correct |
48 ms |
57884 KB |
Output is correct |
69 |
Correct |
51 ms |
58192 KB |
Output is correct |
70 |
Correct |
50 ms |
57936 KB |
Output is correct |
71 |
Correct |
11 ms |
48844 KB |
Output is correct |
72 |
Correct |
13 ms |
50924 KB |
Output is correct |
73 |
Correct |
12 ms |
51036 KB |
Output is correct |
74 |
Correct |
12 ms |
51120 KB |
Output is correct |
75 |
Correct |
11 ms |
51036 KB |
Output is correct |
76 |
Correct |
11 ms |
51036 KB |
Output is correct |
77 |
Correct |
12 ms |
51036 KB |
Output is correct |
78 |
Correct |
12 ms |
50884 KB |
Output is correct |
79 |
Correct |
12 ms |
50916 KB |
Output is correct |
80 |
Correct |
49 ms |
57892 KB |
Output is correct |
81 |
Correct |
56 ms |
57676 KB |
Output is correct |
82 |
Correct |
49 ms |
57936 KB |
Output is correct |
83 |
Correct |
48 ms |
57936 KB |
Output is correct |
84 |
Correct |
11 ms |
51032 KB |
Output is correct |
85 |
Correct |
11 ms |
51036 KB |
Output is correct |
86 |
Correct |
11 ms |
51036 KB |
Output is correct |
87 |
Correct |
11 ms |
51288 KB |
Output is correct |
88 |
Correct |
11 ms |
50924 KB |
Output is correct |
89 |
Correct |
11 ms |
51036 KB |
Output is correct |
90 |
Correct |
11 ms |
51036 KB |
Output is correct |
91 |
Correct |
12 ms |
51036 KB |
Output is correct |
92 |
Correct |
13 ms |
51036 KB |
Output is correct |
93 |
Correct |
11 ms |
51036 KB |
Output is correct |
94 |
Correct |
11 ms |
50780 KB |
Output is correct |
95 |
Correct |
11 ms |
50780 KB |
Output is correct |
96 |
Correct |
11 ms |
50660 KB |
Output is correct |
97 |
Correct |
10 ms |
50680 KB |
Output is correct |
98 |
Correct |
10 ms |
50780 KB |
Output is correct |
99 |
Correct |
11 ms |
50888 KB |
Output is correct |
100 |
Correct |
10 ms |
50780 KB |
Output is correct |
101 |
Correct |
11 ms |
50668 KB |
Output is correct |
102 |
Correct |
11 ms |
50780 KB |
Output is correct |
103 |
Correct |
11 ms |
50780 KB |
Output is correct |
104 |
Correct |
14 ms |
51548 KB |
Output is correct |
105 |
Correct |
19 ms |
53072 KB |
Output is correct |
106 |
Correct |
12 ms |
50776 KB |
Output is correct |
107 |
Correct |
26 ms |
55132 KB |
Output is correct |
108 |
Correct |
33 ms |
57504 KB |
Output is correct |
109 |
Correct |
11 ms |
50780 KB |
Output is correct |
110 |
Correct |
40 ms |
58336 KB |
Output is correct |
111 |
Correct |
43 ms |
59728 KB |
Output is correct |
112 |
Correct |
11 ms |
50780 KB |
Output is correct |
113 |
Correct |
60 ms |
65536 KB |
Output is correct |
114 |
Correct |
26 ms |
55520 KB |
Output is correct |
115 |
Incorrect |
26 ms |
55516 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |