#include "dreaming.h"
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y) for (ll i = x; i <= y; i ++)
#define FOr(i,x,y) for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to... Red
using namespace std;
const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;
const int M = 22;
const int pri = 997;
const int Magic = 2101;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
vector < int > comp;
vector < pair < int, int > > g[N];
int n, m, k;
int u[N];
int p[N];
int col;
int dp[N];
int h[N];
int ans;
void dfs (int v, int par = 0) {
u[v] = 1;
comp.pb(v);
for (auto to : g[v]) {
if (to.F != par) {
h[to.F] = h[v] + to.S;
p[to.F] = v;
dfs(to.F, v);
}
}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
n = N, m = M, k = L;
for (int i = 1; i <= m; i ++) {
int l, r, x;
l = A[i - 1], r = B[i - 1], x = T[i - 1];
g[l].pb(mp(r, x));
g[r].pb(mp(l, x));
}
int ans = 0;
vector < int > vv;
for (int i = 0; i < n; i ++) {
if (!u[i]) {
col ++;
p[i] = -1;
comp.clear();
h[i] = 0;
dfs (i);
int mx = i;
for (auto e : comp)
if (h[e] > h[mx]) mx = e;
p[mx] = -1;
comp.clear();
h[mx] = 0;
dfs(mx);
for (auto e : comp)
if (h[e] > h[mx]) mx = e;
ans = max(ans, h[mx]);
//cout << mx << ' ' << h[mx] << '\n';
int half = h[mx];
for (int v = mx; ~v; v = p[v]) {
half = min(half, max(h[v], abs(h[v] - h[mx])));
}
vv.pb(half);
}
}
sort(every(vv));
reverse(every(vv));
if (vv.size() >= 2)
ans = max(ans, vv[0] + vv[1] + k);
if (vv.size() >= 3)
ans = max(ans, vv[1] + vv[2] + k * 2);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
24180 KB |
Output is correct |
2 |
Correct |
79 ms |
24224 KB |
Output is correct |
3 |
Correct |
53 ms |
20852 KB |
Output is correct |
4 |
Correct |
22 ms |
16128 KB |
Output is correct |
5 |
Correct |
20 ms |
15328 KB |
Output is correct |
6 |
Correct |
28 ms |
16640 KB |
Output is correct |
7 |
Correct |
14 ms |
14592 KB |
Output is correct |
8 |
Correct |
40 ms |
17932 KB |
Output is correct |
9 |
Correct |
46 ms |
19320 KB |
Output is correct |
10 |
Correct |
13 ms |
14592 KB |
Output is correct |
11 |
Correct |
59 ms |
20856 KB |
Output is correct |
12 |
Correct |
67 ms |
22484 KB |
Output is correct |
13 |
Correct |
14 ms |
14500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
24180 KB |
Output is correct |
2 |
Correct |
79 ms |
24224 KB |
Output is correct |
3 |
Correct |
53 ms |
20852 KB |
Output is correct |
4 |
Correct |
22 ms |
16128 KB |
Output is correct |
5 |
Correct |
20 ms |
15328 KB |
Output is correct |
6 |
Correct |
28 ms |
16640 KB |
Output is correct |
7 |
Correct |
14 ms |
14592 KB |
Output is correct |
8 |
Correct |
40 ms |
17932 KB |
Output is correct |
9 |
Correct |
46 ms |
19320 KB |
Output is correct |
10 |
Correct |
13 ms |
14592 KB |
Output is correct |
11 |
Correct |
59 ms |
20856 KB |
Output is correct |
12 |
Correct |
67 ms |
22484 KB |
Output is correct |
13 |
Correct |
14 ms |
14500 KB |
Output is correct |
14 |
Correct |
13 ms |
14464 KB |
Output is correct |
15 |
Correct |
13 ms |
14464 KB |
Output is correct |
16 |
Correct |
13 ms |
14464 KB |
Output is correct |
17 |
Correct |
14 ms |
14436 KB |
Output is correct |
18 |
Correct |
14 ms |
14464 KB |
Output is correct |
19 |
Correct |
14 ms |
14464 KB |
Output is correct |
20 |
Correct |
13 ms |
14464 KB |
Output is correct |
21 |
Correct |
13 ms |
14464 KB |
Output is correct |
22 |
Correct |
13 ms |
14464 KB |
Output is correct |
23 |
Correct |
13 ms |
14464 KB |
Output is correct |
24 |
Correct |
13 ms |
14464 KB |
Output is correct |
25 |
Correct |
13 ms |
14464 KB |
Output is correct |
26 |
Correct |
13 ms |
14464 KB |
Output is correct |
27 |
Correct |
14 ms |
14464 KB |
Output is correct |
28 |
Correct |
12 ms |
14464 KB |
Output is correct |
29 |
Correct |
13 ms |
14424 KB |
Output is correct |
30 |
Correct |
14 ms |
14464 KB |
Output is correct |
31 |
Correct |
13 ms |
14464 KB |
Output is correct |
32 |
Correct |
13 ms |
14464 KB |
Output is correct |
33 |
Correct |
13 ms |
14464 KB |
Output is correct |
34 |
Correct |
13 ms |
14460 KB |
Output is correct |
35 |
Correct |
13 ms |
14464 KB |
Output is correct |
36 |
Correct |
13 ms |
14464 KB |
Output is correct |
37 |
Correct |
14 ms |
14464 KB |
Output is correct |
38 |
Correct |
14 ms |
14464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
24180 KB |
Output is correct |
2 |
Correct |
79 ms |
24224 KB |
Output is correct |
3 |
Correct |
53 ms |
20852 KB |
Output is correct |
4 |
Correct |
22 ms |
16128 KB |
Output is correct |
5 |
Correct |
20 ms |
15328 KB |
Output is correct |
6 |
Correct |
28 ms |
16640 KB |
Output is correct |
7 |
Correct |
14 ms |
14592 KB |
Output is correct |
8 |
Correct |
40 ms |
17932 KB |
Output is correct |
9 |
Correct |
46 ms |
19320 KB |
Output is correct |
10 |
Correct |
13 ms |
14592 KB |
Output is correct |
11 |
Correct |
59 ms |
20856 KB |
Output is correct |
12 |
Correct |
67 ms |
22484 KB |
Output is correct |
13 |
Correct |
14 ms |
14500 KB |
Output is correct |
14 |
Correct |
13 ms |
14464 KB |
Output is correct |
15 |
Correct |
13 ms |
14464 KB |
Output is correct |
16 |
Correct |
13 ms |
14464 KB |
Output is correct |
17 |
Correct |
14 ms |
14436 KB |
Output is correct |
18 |
Correct |
14 ms |
14464 KB |
Output is correct |
19 |
Correct |
14 ms |
14464 KB |
Output is correct |
20 |
Correct |
13 ms |
14464 KB |
Output is correct |
21 |
Correct |
13 ms |
14464 KB |
Output is correct |
22 |
Correct |
13 ms |
14464 KB |
Output is correct |
23 |
Correct |
13 ms |
14464 KB |
Output is correct |
24 |
Correct |
13 ms |
14464 KB |
Output is correct |
25 |
Correct |
13 ms |
14464 KB |
Output is correct |
26 |
Correct |
13 ms |
14464 KB |
Output is correct |
27 |
Correct |
14 ms |
14464 KB |
Output is correct |
28 |
Correct |
12 ms |
14464 KB |
Output is correct |
29 |
Correct |
13 ms |
14424 KB |
Output is correct |
30 |
Correct |
14 ms |
14464 KB |
Output is correct |
31 |
Correct |
13 ms |
14464 KB |
Output is correct |
32 |
Correct |
13 ms |
14464 KB |
Output is correct |
33 |
Correct |
13 ms |
14464 KB |
Output is correct |
34 |
Correct |
13 ms |
14460 KB |
Output is correct |
35 |
Correct |
13 ms |
14464 KB |
Output is correct |
36 |
Correct |
13 ms |
14464 KB |
Output is correct |
37 |
Correct |
14 ms |
14464 KB |
Output is correct |
38 |
Correct |
14 ms |
14464 KB |
Output is correct |
39 |
Correct |
78 ms |
24308 KB |
Output is correct |
40 |
Correct |
69 ms |
24180 KB |
Output is correct |
41 |
Correct |
56 ms |
20896 KB |
Output is correct |
42 |
Correct |
21 ms |
15872 KB |
Output is correct |
43 |
Correct |
13 ms |
14464 KB |
Output is correct |
44 |
Correct |
14 ms |
14464 KB |
Output is correct |
45 |
Correct |
13 ms |
14464 KB |
Output is correct |
46 |
Correct |
14 ms |
14464 KB |
Output is correct |
47 |
Correct |
13 ms |
14464 KB |
Output is correct |
48 |
Correct |
14 ms |
14592 KB |
Output is correct |
49 |
Correct |
13 ms |
14464 KB |
Output is correct |
50 |
Correct |
14 ms |
14464 KB |
Output is correct |
51 |
Correct |
13 ms |
14464 KB |
Output is correct |
52 |
Correct |
14 ms |
14464 KB |
Output is correct |
53 |
Correct |
13 ms |
14464 KB |
Output is correct |
54 |
Correct |
13 ms |
14464 KB |
Output is correct |
55 |
Correct |
14 ms |
14464 KB |
Output is correct |
56 |
Correct |
14 ms |
14464 KB |
Output is correct |
57 |
Correct |
80 ms |
21432 KB |
Output is correct |
58 |
Correct |
94 ms |
21116 KB |
Output is correct |
59 |
Correct |
100 ms |
21492 KB |
Output is correct |
60 |
Correct |
86 ms |
20984 KB |
Output is correct |
61 |
Correct |
79 ms |
21236 KB |
Output is correct |
62 |
Correct |
90 ms |
20984 KB |
Output is correct |
63 |
Correct |
74 ms |
21112 KB |
Output is correct |
64 |
Incorrect |
78 ms |
21092 KB |
Output isn't correct |
65 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
18304 KB |
Output is correct |
2 |
Correct |
49 ms |
18340 KB |
Output is correct |
3 |
Correct |
47 ms |
18296 KB |
Output is correct |
4 |
Correct |
41 ms |
18304 KB |
Output is correct |
5 |
Correct |
42 ms |
18296 KB |
Output is correct |
6 |
Correct |
50 ms |
18808 KB |
Output is correct |
7 |
Correct |
40 ms |
18432 KB |
Output is correct |
8 |
Correct |
38 ms |
18176 KB |
Output is correct |
9 |
Correct |
37 ms |
18168 KB |
Output is correct |
10 |
Correct |
38 ms |
18432 KB |
Output is correct |
11 |
Correct |
13 ms |
14464 KB |
Output is correct |
12 |
Correct |
18 ms |
16380 KB |
Output is correct |
13 |
Correct |
19 ms |
16252 KB |
Output is correct |
14 |
Correct |
18 ms |
16252 KB |
Output is correct |
15 |
Correct |
19 ms |
16252 KB |
Output is correct |
16 |
Correct |
18 ms |
16252 KB |
Output is correct |
17 |
Correct |
18 ms |
16164 KB |
Output is correct |
18 |
Correct |
20 ms |
16380 KB |
Output is correct |
19 |
Correct |
18 ms |
16252 KB |
Output is correct |
20 |
Correct |
13 ms |
14464 KB |
Output is correct |
21 |
Correct |
12 ms |
14464 KB |
Output is correct |
22 |
Correct |
13 ms |
14464 KB |
Output is correct |
23 |
Correct |
18 ms |
16280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
24180 KB |
Output is correct |
2 |
Correct |
79 ms |
24224 KB |
Output is correct |
3 |
Correct |
53 ms |
20852 KB |
Output is correct |
4 |
Correct |
22 ms |
16128 KB |
Output is correct |
5 |
Correct |
20 ms |
15328 KB |
Output is correct |
6 |
Correct |
28 ms |
16640 KB |
Output is correct |
7 |
Correct |
14 ms |
14592 KB |
Output is correct |
8 |
Correct |
40 ms |
17932 KB |
Output is correct |
9 |
Correct |
46 ms |
19320 KB |
Output is correct |
10 |
Correct |
13 ms |
14592 KB |
Output is correct |
11 |
Correct |
59 ms |
20856 KB |
Output is correct |
12 |
Correct |
67 ms |
22484 KB |
Output is correct |
13 |
Correct |
14 ms |
14500 KB |
Output is correct |
14 |
Correct |
14 ms |
14464 KB |
Output is correct |
15 |
Correct |
15 ms |
14592 KB |
Output is correct |
16 |
Correct |
16 ms |
14592 KB |
Output is correct |
17 |
Correct |
15 ms |
14592 KB |
Output is correct |
18 |
Correct |
15 ms |
14564 KB |
Output is correct |
19 |
Correct |
15 ms |
14592 KB |
Output is correct |
20 |
Correct |
15 ms |
14464 KB |
Output is correct |
21 |
Correct |
15 ms |
14592 KB |
Output is correct |
22 |
Correct |
15 ms |
14592 KB |
Output is correct |
23 |
Correct |
13 ms |
14464 KB |
Output is correct |
24 |
Correct |
15 ms |
14464 KB |
Output is correct |
25 |
Correct |
14 ms |
14584 KB |
Output is correct |
26 |
Correct |
13 ms |
14464 KB |
Output is correct |
27 |
Correct |
14 ms |
14464 KB |
Output is correct |
28 |
Correct |
14 ms |
14464 KB |
Output is correct |
29 |
Correct |
14 ms |
14464 KB |
Output is correct |
30 |
Correct |
15 ms |
14464 KB |
Output is correct |
31 |
Correct |
13 ms |
14464 KB |
Output is correct |
32 |
Correct |
13 ms |
14464 KB |
Output is correct |
33 |
Correct |
14 ms |
14464 KB |
Output is correct |
34 |
Correct |
14 ms |
14464 KB |
Output is correct |
35 |
Correct |
14 ms |
14464 KB |
Output is correct |
36 |
Correct |
14 ms |
14464 KB |
Output is correct |
37 |
Correct |
13 ms |
14464 KB |
Output is correct |
38 |
Correct |
14 ms |
14464 KB |
Output is correct |
39 |
Correct |
14 ms |
14464 KB |
Output is correct |
40 |
Correct |
14 ms |
14464 KB |
Output is correct |
41 |
Correct |
15 ms |
14464 KB |
Output is correct |
42 |
Correct |
16 ms |
14720 KB |
Output is correct |
43 |
Correct |
15 ms |
14720 KB |
Output is correct |
44 |
Correct |
14 ms |
14592 KB |
Output is correct |
45 |
Correct |
14 ms |
14592 KB |
Output is correct |
46 |
Correct |
16 ms |
14720 KB |
Output is correct |
47 |
Correct |
15 ms |
14720 KB |
Output is correct |
48 |
Correct |
15 ms |
14592 KB |
Output is correct |
49 |
Correct |
14 ms |
14592 KB |
Output is correct |
50 |
Correct |
15 ms |
14592 KB |
Output is correct |
51 |
Correct |
16 ms |
14720 KB |
Output is correct |
52 |
Correct |
14 ms |
14464 KB |
Output is correct |
53 |
Correct |
15 ms |
14592 KB |
Output is correct |
54 |
Correct |
15 ms |
14712 KB |
Output is correct |
55 |
Correct |
14 ms |
14592 KB |
Output is correct |
56 |
Correct |
15 ms |
14592 KB |
Output is correct |
57 |
Correct |
16 ms |
14592 KB |
Output is correct |
58 |
Correct |
15 ms |
14592 KB |
Output is correct |
59 |
Correct |
14 ms |
14592 KB |
Output is correct |
60 |
Correct |
15 ms |
14592 KB |
Output is correct |
61 |
Correct |
15 ms |
14792 KB |
Output is correct |
62 |
Correct |
15 ms |
14592 KB |
Output is correct |
63 |
Correct |
15 ms |
14592 KB |
Output is correct |
64 |
Correct |
16 ms |
14720 KB |
Output is correct |
65 |
Correct |
19 ms |
14592 KB |
Output is correct |
66 |
Correct |
14 ms |
14592 KB |
Output is correct |
67 |
Correct |
14 ms |
14592 KB |
Output is correct |
68 |
Correct |
14 ms |
14592 KB |
Output is correct |
69 |
Correct |
14 ms |
14464 KB |
Output is correct |
70 |
Correct |
15 ms |
14592 KB |
Output is correct |
71 |
Correct |
15 ms |
14592 KB |
Output is correct |
72 |
Correct |
14 ms |
14592 KB |
Output is correct |
73 |
Correct |
14 ms |
14544 KB |
Output is correct |
74 |
Correct |
15 ms |
14592 KB |
Output is correct |
75 |
Correct |
15 ms |
14592 KB |
Output is correct |
76 |
Correct |
15 ms |
14592 KB |
Output is correct |
77 |
Correct |
23 ms |
14584 KB |
Output is correct |
78 |
Correct |
14 ms |
14592 KB |
Output is correct |
79 |
Correct |
15 ms |
14592 KB |
Output is correct |
80 |
Correct |
15 ms |
14592 KB |
Output is correct |
81 |
Correct |
14 ms |
14592 KB |
Output is correct |
82 |
Correct |
15 ms |
14592 KB |
Output is correct |
83 |
Correct |
16 ms |
14592 KB |
Output is correct |
84 |
Correct |
16 ms |
14592 KB |
Output is correct |
85 |
Correct |
15 ms |
14592 KB |
Output is correct |
86 |
Correct |
15 ms |
14592 KB |
Output is correct |
87 |
Correct |
15 ms |
14592 KB |
Output is correct |
88 |
Correct |
15 ms |
14592 KB |
Output is correct |
89 |
Correct |
15 ms |
14592 KB |
Output is correct |
90 |
Correct |
13 ms |
14464 KB |
Output is correct |
91 |
Correct |
13 ms |
14464 KB |
Output is correct |
92 |
Correct |
13 ms |
14464 KB |
Output is correct |
93 |
Correct |
13 ms |
14464 KB |
Output is correct |
94 |
Correct |
13 ms |
14464 KB |
Output is correct |
95 |
Correct |
14 ms |
14464 KB |
Output is correct |
96 |
Correct |
13 ms |
14464 KB |
Output is correct |
97 |
Correct |
13 ms |
14464 KB |
Output is correct |
98 |
Correct |
13 ms |
14464 KB |
Output is correct |
99 |
Correct |
13 ms |
14464 KB |
Output is correct |
100 |
Correct |
13 ms |
14464 KB |
Output is correct |
101 |
Correct |
14 ms |
14464 KB |
Output is correct |
102 |
Correct |
13 ms |
14592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
24180 KB |
Output is correct |
2 |
Correct |
79 ms |
24224 KB |
Output is correct |
3 |
Correct |
53 ms |
20852 KB |
Output is correct |
4 |
Correct |
22 ms |
16128 KB |
Output is correct |
5 |
Correct |
20 ms |
15328 KB |
Output is correct |
6 |
Correct |
28 ms |
16640 KB |
Output is correct |
7 |
Correct |
14 ms |
14592 KB |
Output is correct |
8 |
Correct |
40 ms |
17932 KB |
Output is correct |
9 |
Correct |
46 ms |
19320 KB |
Output is correct |
10 |
Correct |
13 ms |
14592 KB |
Output is correct |
11 |
Correct |
59 ms |
20856 KB |
Output is correct |
12 |
Correct |
67 ms |
22484 KB |
Output is correct |
13 |
Correct |
14 ms |
14500 KB |
Output is correct |
14 |
Correct |
13 ms |
14464 KB |
Output is correct |
15 |
Correct |
13 ms |
14464 KB |
Output is correct |
16 |
Correct |
13 ms |
14464 KB |
Output is correct |
17 |
Correct |
14 ms |
14436 KB |
Output is correct |
18 |
Correct |
14 ms |
14464 KB |
Output is correct |
19 |
Correct |
14 ms |
14464 KB |
Output is correct |
20 |
Correct |
13 ms |
14464 KB |
Output is correct |
21 |
Correct |
13 ms |
14464 KB |
Output is correct |
22 |
Correct |
13 ms |
14464 KB |
Output is correct |
23 |
Correct |
13 ms |
14464 KB |
Output is correct |
24 |
Correct |
13 ms |
14464 KB |
Output is correct |
25 |
Correct |
13 ms |
14464 KB |
Output is correct |
26 |
Correct |
13 ms |
14464 KB |
Output is correct |
27 |
Correct |
14 ms |
14464 KB |
Output is correct |
28 |
Correct |
12 ms |
14464 KB |
Output is correct |
29 |
Correct |
13 ms |
14424 KB |
Output is correct |
30 |
Correct |
14 ms |
14464 KB |
Output is correct |
31 |
Correct |
13 ms |
14464 KB |
Output is correct |
32 |
Correct |
13 ms |
14464 KB |
Output is correct |
33 |
Correct |
13 ms |
14464 KB |
Output is correct |
34 |
Correct |
13 ms |
14460 KB |
Output is correct |
35 |
Correct |
13 ms |
14464 KB |
Output is correct |
36 |
Correct |
13 ms |
14464 KB |
Output is correct |
37 |
Correct |
14 ms |
14464 KB |
Output is correct |
38 |
Correct |
14 ms |
14464 KB |
Output is correct |
39 |
Correct |
78 ms |
24308 KB |
Output is correct |
40 |
Correct |
69 ms |
24180 KB |
Output is correct |
41 |
Correct |
56 ms |
20896 KB |
Output is correct |
42 |
Correct |
21 ms |
15872 KB |
Output is correct |
43 |
Correct |
13 ms |
14464 KB |
Output is correct |
44 |
Correct |
14 ms |
14464 KB |
Output is correct |
45 |
Correct |
13 ms |
14464 KB |
Output is correct |
46 |
Correct |
14 ms |
14464 KB |
Output is correct |
47 |
Correct |
13 ms |
14464 KB |
Output is correct |
48 |
Correct |
14 ms |
14592 KB |
Output is correct |
49 |
Correct |
13 ms |
14464 KB |
Output is correct |
50 |
Correct |
14 ms |
14464 KB |
Output is correct |
51 |
Correct |
13 ms |
14464 KB |
Output is correct |
52 |
Correct |
14 ms |
14464 KB |
Output is correct |
53 |
Correct |
13 ms |
14464 KB |
Output is correct |
54 |
Correct |
13 ms |
14464 KB |
Output is correct |
55 |
Correct |
14 ms |
14464 KB |
Output is correct |
56 |
Correct |
14 ms |
14464 KB |
Output is correct |
57 |
Correct |
80 ms |
21432 KB |
Output is correct |
58 |
Correct |
94 ms |
21116 KB |
Output is correct |
59 |
Correct |
100 ms |
21492 KB |
Output is correct |
60 |
Correct |
86 ms |
20984 KB |
Output is correct |
61 |
Correct |
79 ms |
21236 KB |
Output is correct |
62 |
Correct |
90 ms |
20984 KB |
Output is correct |
63 |
Correct |
74 ms |
21112 KB |
Output is correct |
64 |
Incorrect |
78 ms |
21092 KB |
Output isn't correct |
65 |
Halted |
0 ms |
0 KB |
- |