#include "dreaming.h"
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
const int MAX_N = 1e5 + 5;
vii tree[MAX_N];
int deg[MAX_N];
bitset<MAX_N> visited;
pii DfsFar(int node, int parent, int d) {
visited[node] = true;
pii p = {d, node};
for (auto [neighbor, w] : tree[node]) {
if (neighbor != parent) {
chkmax(p, DfsFar(neighbor, node, d + w));
}
}
return p;
}
bool DfsPath(int node, int parent, int end, vii &path) {
if (node == end) {
path.push_back({node, 0});
return true;
}
for (auto [neighbor, w] : tree[node]) {
if (neighbor != parent && DfsPath(neighbor, node, end, path)) {
path.push_back({node, w});
return true;
}
}
return false;
}
int ans = 0;
int FindRadius(int node) {
int v = DfsFar(node, -1, 0).y;
auto [diameter, u] = DfsFar(v, -1, 0);
int x = diameter;
int dist = 0;
vii path;
DfsPath(v, -1, u, path);
for (auto [node, w] : path) {
chkmin(x, max(dist, diameter - dist));
dist += w;
}
chkmax(ans, diameter);
return x;
}
int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
for (int i = 0; i < m; i++) {
deg[a[i]]++, deg[b[i]]++;
}
for (int i = 0; i < n; i++) {
tree[i].reserve(deg[i]);
}
for (int i = 0; i < m; i++) {
tree[a[i]].push_back({b[i], t[i]});
tree[b[i]].push_back({a[i], t[i]});
}
int s = 0;
for (int i = 0; i < n; i++) {
if (!visited[i]) {
s += FindRadius(i) + l;
}
}
chkmax(ans, s - l);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
16600 KB |
Output is correct |
2 |
Correct |
54 ms |
16860 KB |
Output is correct |
3 |
Correct |
34 ms |
11944 KB |
Output is correct |
4 |
Correct |
7 ms |
4972 KB |
Output is correct |
5 |
Correct |
6 ms |
3796 KB |
Output is correct |
6 |
Correct |
11 ms |
6100 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
22 ms |
7400 KB |
Output is correct |
9 |
Correct |
27 ms |
9572 KB |
Output is correct |
10 |
Correct |
2 ms |
2656 KB |
Output is correct |
11 |
Correct |
38 ms |
11244 KB |
Output is correct |
12 |
Correct |
44 ms |
14284 KB |
Output is correct |
13 |
Correct |
2 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2584 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2656 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2656 KB |
Output is correct |
9 |
Correct |
2 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Correct |
2 ms |
2652 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2652 KB |
Output is correct |
17 |
Correct |
2 ms |
2652 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 |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 ms |
2652 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
16600 KB |
Output is correct |
2 |
Correct |
54 ms |
16860 KB |
Output is correct |
3 |
Correct |
34 ms |
11944 KB |
Output is correct |
4 |
Correct |
7 ms |
4972 KB |
Output is correct |
5 |
Correct |
6 ms |
3796 KB |
Output is correct |
6 |
Correct |
11 ms |
6100 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
22 ms |
7400 KB |
Output is correct |
9 |
Correct |
27 ms |
9572 KB |
Output is correct |
10 |
Correct |
2 ms |
2656 KB |
Output is correct |
11 |
Correct |
38 ms |
11244 KB |
Output is correct |
12 |
Correct |
44 ms |
14284 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 |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2584 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2656 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2656 KB |
Output is correct |
22 |
Correct |
2 ms |
2648 KB |
Output is correct |
23 |
Correct |
1 ms |
2644 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
2 ms |
2644 KB |
Output is correct |
28 |
Correct |
2 ms |
2644 KB |
Output is correct |
29 |
Correct |
2 ms |
2652 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2644 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 |
2644 KB |
Output is correct |
35 |
Correct |
2 ms |
2644 KB |
Output is correct |
36 |
Correct |
2 ms |
2652 KB |
Output is correct |
37 |
Correct |
2 ms |
2644 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
39 |
Correct |
56 ms |
17796 KB |
Output is correct |
40 |
Correct |
52 ms |
17824 KB |
Output is correct |
41 |
Correct |
31 ms |
12680 KB |
Output is correct |
42 |
Correct |
9 ms |
4992 KB |
Output is correct |
43 |
Correct |
2 ms |
2644 KB |
Output is correct |
44 |
Correct |
1 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 |
2652 KB |
Output is correct |
48 |
Correct |
2 ms |
2656 KB |
Output is correct |
49 |
Correct |
2 ms |
2656 KB |
Output is correct |
50 |
Correct |
2 ms |
2644 KB |
Output is correct |
51 |
Correct |
2 ms |
2660 KB |
Output is correct |
52 |
Correct |
2 ms |
2644 KB |
Output is correct |
53 |
Correct |
2 ms |
2644 KB |
Output is correct |
54 |
Correct |
2 ms |
2644 KB |
Output is correct |
55 |
Correct |
1 ms |
2644 KB |
Output is correct |
56 |
Correct |
2 ms |
2660 KB |
Output is correct |
57 |
Correct |
45 ms |
8680 KB |
Output is correct |
58 |
Correct |
48 ms |
8660 KB |
Output is correct |
59 |
Correct |
45 ms |
8940 KB |
Output is correct |
60 |
Correct |
44 ms |
8904 KB |
Output is correct |
61 |
Correct |
47 ms |
9036 KB |
Output is correct |
62 |
Correct |
45 ms |
9036 KB |
Output is correct |
63 |
Correct |
42 ms |
8988 KB |
Output is correct |
64 |
Correct |
40 ms |
8900 KB |
Output is correct |
65 |
Correct |
42 ms |
9176 KB |
Output is correct |
66 |
Correct |
41 ms |
9164 KB |
Output is correct |
67 |
Correct |
43 ms |
8908 KB |
Output is correct |
68 |
Correct |
48 ms |
8872 KB |
Output is correct |
69 |
Correct |
48 ms |
9244 KB |
Output is correct |
70 |
Correct |
45 ms |
9124 KB |
Output is correct |
71 |
Correct |
2 ms |
2644 KB |
Output is correct |
72 |
Correct |
3 ms |
2772 KB |
Output is correct |
73 |
Correct |
3 ms |
2796 KB |
Output is correct |
74 |
Correct |
3 ms |
2796 KB |
Output is correct |
75 |
Correct |
3 ms |
2772 KB |
Output is correct |
76 |
Correct |
3 ms |
2772 KB |
Output is correct |
77 |
Correct |
3 ms |
2772 KB |
Output is correct |
78 |
Correct |
3 ms |
2772 KB |
Output is correct |
79 |
Correct |
3 ms |
2772 KB |
Output is correct |
80 |
Correct |
47 ms |
8828 KB |
Output is correct |
81 |
Correct |
45 ms |
8948 KB |
Output is correct |
82 |
Correct |
44 ms |
9040 KB |
Output is correct |
83 |
Correct |
44 ms |
9036 KB |
Output is correct |
84 |
Correct |
2 ms |
2772 KB |
Output is correct |
85 |
Correct |
2 ms |
2772 KB |
Output is correct |
86 |
Correct |
3 ms |
2772 KB |
Output is correct |
87 |
Correct |
2 ms |
2796 KB |
Output is correct |
88 |
Correct |
3 ms |
2792 KB |
Output is correct |
89 |
Correct |
3 ms |
2792 KB |
Output is correct |
90 |
Correct |
3 ms |
2788 KB |
Output is correct |
91 |
Correct |
3 ms |
2796 KB |
Output is correct |
92 |
Correct |
3 ms |
2832 KB |
Output is correct |
93 |
Correct |
2 ms |
2772 KB |
Output is correct |
94 |
Correct |
2 ms |
2644 KB |
Output is correct |
95 |
Correct |
2 ms |
2644 KB |
Output is correct |
96 |
Correct |
2 ms |
2644 KB |
Output is correct |
97 |
Correct |
2 ms |
2656 KB |
Output is correct |
98 |
Correct |
2 ms |
2644 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 |
2644 KB |
Output is correct |
102 |
Correct |
1 ms |
2644 KB |
Output is correct |
103 |
Correct |
2 ms |
2644 KB |
Output is correct |
104 |
Correct |
6 ms |
3824 KB |
Output is correct |
105 |
Correct |
11 ms |
6096 KB |
Output is correct |
106 |
Correct |
2 ms |
2644 KB |
Output is correct |
107 |
Correct |
20 ms |
7604 KB |
Output is correct |
108 |
Correct |
25 ms |
10028 KB |
Output is correct |
109 |
Correct |
2 ms |
2660 KB |
Output is correct |
110 |
Correct |
39 ms |
12112 KB |
Output is correct |
111 |
Correct |
45 ms |
15100 KB |
Output is correct |
112 |
Correct |
2 ms |
2772 KB |
Output is correct |
113 |
Correct |
68 ms |
19492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
5332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2584 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2656 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2656 KB |
Output is correct |
9 |
Correct |
2 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Correct |
2 ms |
2652 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2652 KB |
Output is correct |
17 |
Correct |
2 ms |
2652 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 |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 ms |
2652 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
26 |
Incorrect |
2 ms |
2660 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
16600 KB |
Output is correct |
2 |
Correct |
54 ms |
16860 KB |
Output is correct |
3 |
Correct |
34 ms |
11944 KB |
Output is correct |
4 |
Correct |
7 ms |
4972 KB |
Output is correct |
5 |
Correct |
6 ms |
3796 KB |
Output is correct |
6 |
Correct |
11 ms |
6100 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
22 ms |
7400 KB |
Output is correct |
9 |
Correct |
27 ms |
9572 KB |
Output is correct |
10 |
Correct |
2 ms |
2656 KB |
Output is correct |
11 |
Correct |
38 ms |
11244 KB |
Output is correct |
12 |
Correct |
44 ms |
14284 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 |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
2 ms |
2584 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2656 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2656 KB |
Output is correct |
22 |
Correct |
2 ms |
2648 KB |
Output is correct |
23 |
Correct |
1 ms |
2644 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2652 KB |
Output is correct |
26 |
Correct |
2 ms |
2652 KB |
Output is correct |
27 |
Correct |
2 ms |
2644 KB |
Output is correct |
28 |
Correct |
2 ms |
2644 KB |
Output is correct |
29 |
Correct |
2 ms |
2652 KB |
Output is correct |
30 |
Correct |
2 ms |
2652 KB |
Output is correct |
31 |
Correct |
2 ms |
2644 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 |
2644 KB |
Output is correct |
35 |
Correct |
2 ms |
2644 KB |
Output is correct |
36 |
Correct |
2 ms |
2652 KB |
Output is correct |
37 |
Correct |
2 ms |
2644 KB |
Output is correct |
38 |
Correct |
2 ms |
2652 KB |
Output is correct |
39 |
Correct |
56 ms |
17796 KB |
Output is correct |
40 |
Correct |
52 ms |
17824 KB |
Output is correct |
41 |
Correct |
31 ms |
12680 KB |
Output is correct |
42 |
Correct |
9 ms |
4992 KB |
Output is correct |
43 |
Correct |
2 ms |
2644 KB |
Output is correct |
44 |
Correct |
1 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 |
2652 KB |
Output is correct |
48 |
Correct |
2 ms |
2656 KB |
Output is correct |
49 |
Correct |
2 ms |
2656 KB |
Output is correct |
50 |
Correct |
2 ms |
2644 KB |
Output is correct |
51 |
Correct |
2 ms |
2660 KB |
Output is correct |
52 |
Correct |
2 ms |
2644 KB |
Output is correct |
53 |
Correct |
2 ms |
2644 KB |
Output is correct |
54 |
Correct |
2 ms |
2644 KB |
Output is correct |
55 |
Correct |
1 ms |
2644 KB |
Output is correct |
56 |
Correct |
2 ms |
2660 KB |
Output is correct |
57 |
Correct |
45 ms |
8680 KB |
Output is correct |
58 |
Correct |
48 ms |
8660 KB |
Output is correct |
59 |
Correct |
45 ms |
8940 KB |
Output is correct |
60 |
Correct |
44 ms |
8904 KB |
Output is correct |
61 |
Correct |
47 ms |
9036 KB |
Output is correct |
62 |
Correct |
45 ms |
9036 KB |
Output is correct |
63 |
Correct |
42 ms |
8988 KB |
Output is correct |
64 |
Correct |
40 ms |
8900 KB |
Output is correct |
65 |
Correct |
42 ms |
9176 KB |
Output is correct |
66 |
Correct |
41 ms |
9164 KB |
Output is correct |
67 |
Correct |
43 ms |
8908 KB |
Output is correct |
68 |
Correct |
48 ms |
8872 KB |
Output is correct |
69 |
Correct |
48 ms |
9244 KB |
Output is correct |
70 |
Correct |
45 ms |
9124 KB |
Output is correct |
71 |
Correct |
2 ms |
2644 KB |
Output is correct |
72 |
Correct |
3 ms |
2772 KB |
Output is correct |
73 |
Correct |
3 ms |
2796 KB |
Output is correct |
74 |
Correct |
3 ms |
2796 KB |
Output is correct |
75 |
Correct |
3 ms |
2772 KB |
Output is correct |
76 |
Correct |
3 ms |
2772 KB |
Output is correct |
77 |
Correct |
3 ms |
2772 KB |
Output is correct |
78 |
Correct |
3 ms |
2772 KB |
Output is correct |
79 |
Correct |
3 ms |
2772 KB |
Output is correct |
80 |
Correct |
47 ms |
8828 KB |
Output is correct |
81 |
Correct |
45 ms |
8948 KB |
Output is correct |
82 |
Correct |
44 ms |
9040 KB |
Output is correct |
83 |
Correct |
44 ms |
9036 KB |
Output is correct |
84 |
Correct |
2 ms |
2772 KB |
Output is correct |
85 |
Correct |
2 ms |
2772 KB |
Output is correct |
86 |
Correct |
3 ms |
2772 KB |
Output is correct |
87 |
Correct |
2 ms |
2796 KB |
Output is correct |
88 |
Correct |
3 ms |
2792 KB |
Output is correct |
89 |
Correct |
3 ms |
2792 KB |
Output is correct |
90 |
Correct |
3 ms |
2788 KB |
Output is correct |
91 |
Correct |
3 ms |
2796 KB |
Output is correct |
92 |
Correct |
3 ms |
2832 KB |
Output is correct |
93 |
Correct |
2 ms |
2772 KB |
Output is correct |
94 |
Correct |
2 ms |
2644 KB |
Output is correct |
95 |
Correct |
2 ms |
2644 KB |
Output is correct |
96 |
Correct |
2 ms |
2644 KB |
Output is correct |
97 |
Correct |
2 ms |
2656 KB |
Output is correct |
98 |
Correct |
2 ms |
2644 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 |
2644 KB |
Output is correct |
102 |
Correct |
1 ms |
2644 KB |
Output is correct |
103 |
Correct |
2 ms |
2644 KB |
Output is correct |
104 |
Correct |
6 ms |
3824 KB |
Output is correct |
105 |
Correct |
11 ms |
6096 KB |
Output is correct |
106 |
Correct |
2 ms |
2644 KB |
Output is correct |
107 |
Correct |
20 ms |
7604 KB |
Output is correct |
108 |
Correct |
25 ms |
10028 KB |
Output is correct |
109 |
Correct |
2 ms |
2660 KB |
Output is correct |
110 |
Correct |
39 ms |
12112 KB |
Output is correct |
111 |
Correct |
45 ms |
15100 KB |
Output is correct |
112 |
Correct |
2 ms |
2772 KB |
Output is correct |
113 |
Correct |
68 ms |
19492 KB |
Output is correct |
114 |
Incorrect |
18 ms |
5332 KB |
Output isn't correct |
115 |
Halted |
0 ms |
0 KB |
- |