#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
const int NN = 100005;
int a[NN], b[NN], t[NN];
vector<pair<int, int>> g[NN];
int vis[NN];
int mx[NN], mx2[NN];
int far[NN];
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
int n, m, l;
n = N, m = M, l = L;
for (int i = 0; i < m; ++i) {
a[i] = A[i];
b[i] = B[i];
t[i] = T[i];
}
for (int i = 0; i < m; ++i) {
g[a[i]].emplace_back(b[i], t[i]);
g[b[i]].emplace_back(a[i], t[i]);
}
int ncc = 0;
vector<int> d(n + 1);
function<void(int, int)> Dfs = [&](int v, int p) {
vis[v] = ncc;
for (auto [u, w] : g[v]) {
if (u != p) {
Dfs(u, v);
mx2[v] = max(mx2[v], mx[u] + w);
if (mx2[v] > mx[v]) {
swap(mx2[v], mx[v]);
}
}
}
d[ncc] = max(d[ncc], mx[v] + mx2[v]);
};
vector<int> mn(n + 1, 1e9);
function<void(int, int, int)> Dfs2 = [&](int v, int p, int up) {
far[v] = max(mx[v], up);
mn[ncc] = min(mn[ncc], far[v]);
for (auto [u, w] : g[v]) {
if (u == p) continue;
int nup = max(up, mx[v] == mx[u] + w ? mx2[v] : mx[v]) + w;
Dfs2(u, v, nup);
}
};
for (int i = 0; i < n; ++i) {
if (!vis[i]) {
//cout << " I: " << i << '\n';
ncc++;
Dfs(i, i);
Dfs2(i, i, 0);
}
}
int ans = max({d[1], d[2], l + mn[1] + mn[2]});
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
16148 KB |
Output is correct |
2 |
Correct |
58 ms |
15584 KB |
Output is correct |
3 |
Correct |
34 ms |
13772 KB |
Output is correct |
4 |
Correct |
7 ms |
4560 KB |
Output is correct |
5 |
Correct |
6 ms |
3796 KB |
Output is correct |
6 |
Correct |
12 ms |
5588 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
25 ms |
8780 KB |
Output is correct |
9 |
Correct |
30 ms |
12176 KB |
Output is correct |
10 |
Correct |
2 ms |
2772 KB |
Output is correct |
11 |
Correct |
44 ms |
13372 KB |
Output is correct |
12 |
Correct |
50 ms |
15192 KB |
Output is correct |
13 |
Correct |
2 ms |
2772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
3 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2664 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2660 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2660 KB |
Output is correct |
22 |
Correct |
3 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 ms |
2644 KB |
Output is correct |
24 |
Correct |
2 ms |
2664 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
16148 KB |
Output is correct |
2 |
Correct |
58 ms |
15584 KB |
Output is correct |
3 |
Correct |
34 ms |
13772 KB |
Output is correct |
4 |
Correct |
7 ms |
4560 KB |
Output is correct |
5 |
Correct |
6 ms |
3796 KB |
Output is correct |
6 |
Correct |
12 ms |
5588 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
25 ms |
8780 KB |
Output is correct |
9 |
Correct |
30 ms |
12176 KB |
Output is correct |
10 |
Correct |
2 ms |
2772 KB |
Output is correct |
11 |
Correct |
44 ms |
13372 KB |
Output is correct |
12 |
Correct |
50 ms |
15192 KB |
Output is correct |
13 |
Correct |
2 ms |
2772 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
1 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
3 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 ms |
2644 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
2644 KB |
Output is correct |
27 |
Correct |
2 ms |
2664 KB |
Output is correct |
28 |
Correct |
1 ms |
2644 KB |
Output is correct |
29 |
Correct |
2 ms |
2644 KB |
Output is correct |
30 |
Correct |
2 ms |
2644 KB |
Output is correct |
31 |
Correct |
2 ms |
2660 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
2 ms |
2644 KB |
Output is correct |
34 |
Correct |
2 ms |
2660 KB |
Output is correct |
35 |
Correct |
3 ms |
2644 KB |
Output is correct |
36 |
Correct |
2 ms |
2644 KB |
Output is correct |
37 |
Correct |
2 ms |
2664 KB |
Output is correct |
38 |
Correct |
2 ms |
2644 KB |
Output is correct |
39 |
Correct |
58 ms |
17352 KB |
Output is correct |
40 |
Correct |
49 ms |
16808 KB |
Output is correct |
41 |
Correct |
32 ms |
14632 KB |
Output is correct |
42 |
Correct |
8 ms |
4840 KB |
Output is correct |
43 |
Correct |
2 ms |
2644 KB |
Output is correct |
44 |
Correct |
2 ms |
2644 KB |
Output is correct |
45 |
Correct |
2 ms |
2644 KB |
Output is correct |
46 |
Correct |
2 ms |
2644 KB |
Output is correct |
47 |
Correct |
2 ms |
2644 KB |
Output is correct |
48 |
Correct |
2 ms |
2660 KB |
Output is correct |
49 |
Correct |
2 ms |
2664 KB |
Output is correct |
50 |
Correct |
2 ms |
2772 KB |
Output is correct |
51 |
Correct |
2 ms |
2668 KB |
Output is correct |
52 |
Correct |
2 ms |
2644 KB |
Output is correct |
53 |
Correct |
2 ms |
2768 KB |
Output is correct |
54 |
Correct |
2 ms |
2644 KB |
Output is correct |
55 |
Correct |
2 ms |
2644 KB |
Output is correct |
56 |
Correct |
2 ms |
2644 KB |
Output is correct |
57 |
Correct |
68 ms |
12680 KB |
Output is correct |
58 |
Correct |
73 ms |
12668 KB |
Output is correct |
59 |
Correct |
71 ms |
12576 KB |
Output is correct |
60 |
Correct |
76 ms |
12608 KB |
Output is correct |
61 |
Correct |
57 ms |
12708 KB |
Output is correct |
62 |
Correct |
60 ms |
12652 KB |
Output is correct |
63 |
Correct |
56 ms |
12344 KB |
Output is correct |
64 |
Correct |
72 ms |
12256 KB |
Output is correct |
65 |
Correct |
63 ms |
12564 KB |
Output is correct |
66 |
Correct |
58 ms |
12620 KB |
Output is correct |
67 |
Correct |
71 ms |
12708 KB |
Output is correct |
68 |
Correct |
62 ms |
12632 KB |
Output is correct |
69 |
Correct |
67 ms |
12940 KB |
Output is correct |
70 |
Correct |
62 ms |
12956 KB |
Output is correct |
71 |
Correct |
2 ms |
2644 KB |
Output is correct |
72 |
Correct |
4 ms |
2900 KB |
Output is correct |
73 |
Correct |
3 ms |
2900 KB |
Output is correct |
74 |
Correct |
3 ms |
2932 KB |
Output is correct |
75 |
Correct |
3 ms |
2900 KB |
Output is correct |
76 |
Correct |
3 ms |
2932 KB |
Output is correct |
77 |
Correct |
3 ms |
3028 KB |
Output is correct |
78 |
Correct |
3 ms |
2972 KB |
Output is correct |
79 |
Correct |
4 ms |
2900 KB |
Output is correct |
80 |
Correct |
81 ms |
12628 KB |
Output is correct |
81 |
Correct |
75 ms |
12528 KB |
Output is correct |
82 |
Correct |
70 ms |
12640 KB |
Output is correct |
83 |
Correct |
62 ms |
12692 KB |
Output is correct |
84 |
Correct |
3 ms |
2932 KB |
Output is correct |
85 |
Correct |
3 ms |
2804 KB |
Output is correct |
86 |
Correct |
3 ms |
2900 KB |
Output is correct |
87 |
Correct |
4 ms |
2900 KB |
Output is correct |
88 |
Correct |
4 ms |
2900 KB |
Output is correct |
89 |
Correct |
5 ms |
2840 KB |
Output is correct |
90 |
Correct |
3 ms |
2900 KB |
Output is correct |
91 |
Correct |
3 ms |
2928 KB |
Output is correct |
92 |
Correct |
3 ms |
2900 KB |
Output is correct |
93 |
Correct |
3 ms |
2900 KB |
Output is correct |
94 |
Correct |
2 ms |
2644 KB |
Output is correct |
95 |
Correct |
2 ms |
2664 KB |
Output is correct |
96 |
Correct |
2 ms |
2644 KB |
Output is correct |
97 |
Correct |
2 ms |
2644 KB |
Output is correct |
98 |
Correct |
1 ms |
2772 KB |
Output is correct |
99 |
Correct |
2 ms |
2644 KB |
Output is correct |
100 |
Correct |
2 ms |
2644 KB |
Output is correct |
101 |
Correct |
2 ms |
2784 KB |
Output is correct |
102 |
Correct |
2 ms |
2696 KB |
Output is correct |
103 |
Correct |
2 ms |
2644 KB |
Output is correct |
104 |
Correct |
10 ms |
3916 KB |
Output is correct |
105 |
Correct |
14 ms |
5864 KB |
Output is correct |
106 |
Correct |
3 ms |
2664 KB |
Output is correct |
107 |
Correct |
23 ms |
8740 KB |
Output is correct |
108 |
Correct |
29 ms |
12112 KB |
Output is correct |
109 |
Correct |
2 ms |
2772 KB |
Output is correct |
110 |
Correct |
41 ms |
13352 KB |
Output is correct |
111 |
Correct |
60 ms |
15316 KB |
Output is correct |
112 |
Correct |
2 ms |
2772 KB |
Output is correct |
113 |
Correct |
78 ms |
24424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
7540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
3 ms |
2644 KB |
Output is correct |
10 |
Correct |
2 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2664 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2660 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2660 KB |
Output is correct |
22 |
Correct |
3 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 ms |
2644 KB |
Output is correct |
24 |
Correct |
2 ms |
2664 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Incorrect |
2 ms |
2772 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
16148 KB |
Output is correct |
2 |
Correct |
58 ms |
15584 KB |
Output is correct |
3 |
Correct |
34 ms |
13772 KB |
Output is correct |
4 |
Correct |
7 ms |
4560 KB |
Output is correct |
5 |
Correct |
6 ms |
3796 KB |
Output is correct |
6 |
Correct |
12 ms |
5588 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
25 ms |
8780 KB |
Output is correct |
9 |
Correct |
30 ms |
12176 KB |
Output is correct |
10 |
Correct |
2 ms |
2772 KB |
Output is correct |
11 |
Correct |
44 ms |
13372 KB |
Output is correct |
12 |
Correct |
50 ms |
15192 KB |
Output is correct |
13 |
Correct |
2 ms |
2772 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
1 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
3 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 ms |
2644 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
2 ms |
2644 KB |
Output is correct |
27 |
Correct |
2 ms |
2664 KB |
Output is correct |
28 |
Correct |
1 ms |
2644 KB |
Output is correct |
29 |
Correct |
2 ms |
2644 KB |
Output is correct |
30 |
Correct |
2 ms |
2644 KB |
Output is correct |
31 |
Correct |
2 ms |
2660 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
2 ms |
2644 KB |
Output is correct |
34 |
Correct |
2 ms |
2660 KB |
Output is correct |
35 |
Correct |
3 ms |
2644 KB |
Output is correct |
36 |
Correct |
2 ms |
2644 KB |
Output is correct |
37 |
Correct |
2 ms |
2664 KB |
Output is correct |
38 |
Correct |
2 ms |
2644 KB |
Output is correct |
39 |
Correct |
58 ms |
17352 KB |
Output is correct |
40 |
Correct |
49 ms |
16808 KB |
Output is correct |
41 |
Correct |
32 ms |
14632 KB |
Output is correct |
42 |
Correct |
8 ms |
4840 KB |
Output is correct |
43 |
Correct |
2 ms |
2644 KB |
Output is correct |
44 |
Correct |
2 ms |
2644 KB |
Output is correct |
45 |
Correct |
2 ms |
2644 KB |
Output is correct |
46 |
Correct |
2 ms |
2644 KB |
Output is correct |
47 |
Correct |
2 ms |
2644 KB |
Output is correct |
48 |
Correct |
2 ms |
2660 KB |
Output is correct |
49 |
Correct |
2 ms |
2664 KB |
Output is correct |
50 |
Correct |
2 ms |
2772 KB |
Output is correct |
51 |
Correct |
2 ms |
2668 KB |
Output is correct |
52 |
Correct |
2 ms |
2644 KB |
Output is correct |
53 |
Correct |
2 ms |
2768 KB |
Output is correct |
54 |
Correct |
2 ms |
2644 KB |
Output is correct |
55 |
Correct |
2 ms |
2644 KB |
Output is correct |
56 |
Correct |
2 ms |
2644 KB |
Output is correct |
57 |
Correct |
68 ms |
12680 KB |
Output is correct |
58 |
Correct |
73 ms |
12668 KB |
Output is correct |
59 |
Correct |
71 ms |
12576 KB |
Output is correct |
60 |
Correct |
76 ms |
12608 KB |
Output is correct |
61 |
Correct |
57 ms |
12708 KB |
Output is correct |
62 |
Correct |
60 ms |
12652 KB |
Output is correct |
63 |
Correct |
56 ms |
12344 KB |
Output is correct |
64 |
Correct |
72 ms |
12256 KB |
Output is correct |
65 |
Correct |
63 ms |
12564 KB |
Output is correct |
66 |
Correct |
58 ms |
12620 KB |
Output is correct |
67 |
Correct |
71 ms |
12708 KB |
Output is correct |
68 |
Correct |
62 ms |
12632 KB |
Output is correct |
69 |
Correct |
67 ms |
12940 KB |
Output is correct |
70 |
Correct |
62 ms |
12956 KB |
Output is correct |
71 |
Correct |
2 ms |
2644 KB |
Output is correct |
72 |
Correct |
4 ms |
2900 KB |
Output is correct |
73 |
Correct |
3 ms |
2900 KB |
Output is correct |
74 |
Correct |
3 ms |
2932 KB |
Output is correct |
75 |
Correct |
3 ms |
2900 KB |
Output is correct |
76 |
Correct |
3 ms |
2932 KB |
Output is correct |
77 |
Correct |
3 ms |
3028 KB |
Output is correct |
78 |
Correct |
3 ms |
2972 KB |
Output is correct |
79 |
Correct |
4 ms |
2900 KB |
Output is correct |
80 |
Correct |
81 ms |
12628 KB |
Output is correct |
81 |
Correct |
75 ms |
12528 KB |
Output is correct |
82 |
Correct |
70 ms |
12640 KB |
Output is correct |
83 |
Correct |
62 ms |
12692 KB |
Output is correct |
84 |
Correct |
3 ms |
2932 KB |
Output is correct |
85 |
Correct |
3 ms |
2804 KB |
Output is correct |
86 |
Correct |
3 ms |
2900 KB |
Output is correct |
87 |
Correct |
4 ms |
2900 KB |
Output is correct |
88 |
Correct |
4 ms |
2900 KB |
Output is correct |
89 |
Correct |
5 ms |
2840 KB |
Output is correct |
90 |
Correct |
3 ms |
2900 KB |
Output is correct |
91 |
Correct |
3 ms |
2928 KB |
Output is correct |
92 |
Correct |
3 ms |
2900 KB |
Output is correct |
93 |
Correct |
3 ms |
2900 KB |
Output is correct |
94 |
Correct |
2 ms |
2644 KB |
Output is correct |
95 |
Correct |
2 ms |
2664 KB |
Output is correct |
96 |
Correct |
2 ms |
2644 KB |
Output is correct |
97 |
Correct |
2 ms |
2644 KB |
Output is correct |
98 |
Correct |
1 ms |
2772 KB |
Output is correct |
99 |
Correct |
2 ms |
2644 KB |
Output is correct |
100 |
Correct |
2 ms |
2644 KB |
Output is correct |
101 |
Correct |
2 ms |
2784 KB |
Output is correct |
102 |
Correct |
2 ms |
2696 KB |
Output is correct |
103 |
Correct |
2 ms |
2644 KB |
Output is correct |
104 |
Correct |
10 ms |
3916 KB |
Output is correct |
105 |
Correct |
14 ms |
5864 KB |
Output is correct |
106 |
Correct |
3 ms |
2664 KB |
Output is correct |
107 |
Correct |
23 ms |
8740 KB |
Output is correct |
108 |
Correct |
29 ms |
12112 KB |
Output is correct |
109 |
Correct |
2 ms |
2772 KB |
Output is correct |
110 |
Correct |
41 ms |
13352 KB |
Output is correct |
111 |
Correct |
60 ms |
15316 KB |
Output is correct |
112 |
Correct |
2 ms |
2772 KB |
Output is correct |
113 |
Correct |
78 ms |
24424 KB |
Output is correct |
114 |
Incorrect |
18 ms |
7540 KB |
Output isn't correct |
115 |
Halted |
0 ms |
0 KB |
- |