# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
897746 |
2024-01-03T15:55:40 Z |
aqxa |
Dreaming (IOI13_dreaming) |
C++17 |
|
120 ms |
34644 KB |
#include <bits/stdc++.h>
using namespace std;
#include "dreaming.h"
using ll = long long;
const int N = 1e5;
#define fs first
#define sc second
#define mp make_pair
vector<pair<int, int>> g[N];
int vis[N], mxd[N], mx[N];
multiset<int> ms[N];
void dfs(int x, int p) {
vis[x] = 1;
for (auto [u, w]: g[x]) {
if (u != p) {
dfs(u, x);
mxd[x] = max(mxd[x], mxd[u] + w);
}
}
}
void dfs2(int x, int p, int f) {
ms[x].insert(f);
for (auto [u, w]: g[x]) {
if (u != p) {
ms[x].insert(mxd[u] + w);
}
}
mx[x] = *(ms[x].rbegin());
for (auto [u, w]: g[x]) {
if (u != p) {
ms[x].erase(ms[x].lower_bound(mxd[u] + w));
dfs2(u, x, *(ms[x].rbegin()) + w);
ms[x].insert(mxd[u] + w);
}
}
}
int dfs3(int x, int p) {
int res = mx[x];
for (auto [u, w]: g[x]) {
if (u == p) continue;
res = min(res, dfs3(u, x));
}
return res;
}
int travelTime(int n, int m, int l, int u[], int v[], int t[]){
for (int i = 0; i < n; ++i) {
vis[i] = 0;
mxd[i] = 0;
mx[i] = 0;
}
for (int i = 0; i < m; ++i) {
g[u[i]].push_back(mp(v[i], t[i]));
g[v[i]].push_back(mp(u[i], t[i]));
}
vector<int> mxdist;
for (int i = 0; i < n; ++i) {
if (!vis[i]) {
dfs(i, -1);
dfs2(i, -1, 0);
mxdist.push_back(dfs3(i, -1));
}
}
sort(mxdist.begin(), mxdist.end());
int ans = 0;
for (int i = 0; i < n; ++i) {
ans = max(ans, mx[i]);
}
int sz = (int) mxdist.size();
if (sz == 1) {
assert(m + 1 == n);
} else {
ans = max(ans, mxdist[sz - 1] + mxdist[sz - 2] + l);
}
// for (int i = 0; i < n; ++i) {
// cout << "! " << i << ' ' << mx[i] << '\n';
// }
return ans;
}
// int32_t main() {
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// int N = 12, M = 8, L = 2;
// int A[]{0,8,2,5,5,1,1,10};
// int B[]{8,2,7,11,1,3,9,6};
// int C[]{4,2,4,3,7,1,5,3};
// cout << "answer: " << travelTime(N, M, L, A, B, C);
// return 0;
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
26708 KB |
Output is correct |
2 |
Correct |
90 ms |
26172 KB |
Output is correct |
3 |
Correct |
39 ms |
22864 KB |
Output is correct |
4 |
Correct |
10 ms |
12124 KB |
Output is correct |
5 |
Correct |
10 ms |
11100 KB |
Output is correct |
6 |
Correct |
18 ms |
13404 KB |
Output is correct |
7 |
Correct |
3 ms |
9560 KB |
Output is correct |
8 |
Correct |
24 ms |
16732 KB |
Output is correct |
9 |
Correct |
36 ms |
20316 KB |
Output is correct |
10 |
Correct |
2 ms |
9564 KB |
Output is correct |
11 |
Correct |
59 ms |
23124 KB |
Output is correct |
12 |
Correct |
106 ms |
25424 KB |
Output is correct |
13 |
Correct |
3 ms |
9816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
9564 KB |
Output is correct |
2 |
Correct |
3 ms |
9564 KB |
Output is correct |
3 |
Correct |
2 ms |
9560 KB |
Output is correct |
4 |
Correct |
2 ms |
9564 KB |
Output is correct |
5 |
Correct |
3 ms |
9716 KB |
Output is correct |
6 |
Correct |
3 ms |
9564 KB |
Output is correct |
7 |
Correct |
2 ms |
9564 KB |
Output is correct |
8 |
Correct |
3 ms |
9560 KB |
Output is correct |
9 |
Correct |
2 ms |
9564 KB |
Output is correct |
10 |
Correct |
2 ms |
9564 KB |
Output is correct |
11 |
Correct |
3 ms |
9564 KB |
Output is correct |
12 |
Correct |
2 ms |
9564 KB |
Output is correct |
13 |
Correct |
2 ms |
9560 KB |
Output is correct |
14 |
Correct |
3 ms |
9564 KB |
Output is correct |
15 |
Correct |
2 ms |
9564 KB |
Output is correct |
16 |
Correct |
2 ms |
9564 KB |
Output is correct |
17 |
Correct |
2 ms |
9664 KB |
Output is correct |
18 |
Correct |
2 ms |
9632 KB |
Output is correct |
19 |
Correct |
3 ms |
9564 KB |
Output is correct |
20 |
Correct |
2 ms |
9636 KB |
Output is correct |
21 |
Correct |
2 ms |
9560 KB |
Output is correct |
22 |
Correct |
3 ms |
9560 KB |
Output is correct |
23 |
Correct |
2 ms |
9644 KB |
Output is correct |
24 |
Correct |
2 ms |
9564 KB |
Output is correct |
25 |
Correct |
2 ms |
9564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
26708 KB |
Output is correct |
2 |
Correct |
90 ms |
26172 KB |
Output is correct |
3 |
Correct |
39 ms |
22864 KB |
Output is correct |
4 |
Correct |
10 ms |
12124 KB |
Output is correct |
5 |
Correct |
10 ms |
11100 KB |
Output is correct |
6 |
Correct |
18 ms |
13404 KB |
Output is correct |
7 |
Correct |
3 ms |
9560 KB |
Output is correct |
8 |
Correct |
24 ms |
16732 KB |
Output is correct |
9 |
Correct |
36 ms |
20316 KB |
Output is correct |
10 |
Correct |
2 ms |
9564 KB |
Output is correct |
11 |
Correct |
59 ms |
23124 KB |
Output is correct |
12 |
Correct |
106 ms |
25424 KB |
Output is correct |
13 |
Correct |
3 ms |
9816 KB |
Output is correct |
14 |
Correct |
2 ms |
9564 KB |
Output is correct |
15 |
Correct |
3 ms |
9564 KB |
Output is correct |
16 |
Correct |
2 ms |
9560 KB |
Output is correct |
17 |
Correct |
2 ms |
9564 KB |
Output is correct |
18 |
Correct |
3 ms |
9716 KB |
Output is correct |
19 |
Correct |
3 ms |
9564 KB |
Output is correct |
20 |
Correct |
2 ms |
9564 KB |
Output is correct |
21 |
Correct |
3 ms |
9560 KB |
Output is correct |
22 |
Correct |
2 ms |
9564 KB |
Output is correct |
23 |
Correct |
2 ms |
9564 KB |
Output is correct |
24 |
Correct |
3 ms |
9564 KB |
Output is correct |
25 |
Correct |
2 ms |
9564 KB |
Output is correct |
26 |
Correct |
2 ms |
9560 KB |
Output is correct |
27 |
Correct |
3 ms |
9564 KB |
Output is correct |
28 |
Correct |
2 ms |
9564 KB |
Output is correct |
29 |
Correct |
2 ms |
9564 KB |
Output is correct |
30 |
Correct |
2 ms |
9664 KB |
Output is correct |
31 |
Correct |
2 ms |
9632 KB |
Output is correct |
32 |
Correct |
3 ms |
9564 KB |
Output is correct |
33 |
Correct |
2 ms |
9636 KB |
Output is correct |
34 |
Correct |
2 ms |
9560 KB |
Output is correct |
35 |
Correct |
3 ms |
9560 KB |
Output is correct |
36 |
Correct |
2 ms |
9644 KB |
Output is correct |
37 |
Correct |
2 ms |
9564 KB |
Output is correct |
38 |
Correct |
2 ms |
9564 KB |
Output is correct |
39 |
Correct |
101 ms |
27812 KB |
Output is correct |
40 |
Correct |
68 ms |
27380 KB |
Output is correct |
41 |
Correct |
49 ms |
23636 KB |
Output is correct |
42 |
Correct |
8 ms |
12120 KB |
Output is correct |
43 |
Correct |
2 ms |
9564 KB |
Output is correct |
44 |
Correct |
2 ms |
9564 KB |
Output is correct |
45 |
Correct |
3 ms |
9560 KB |
Output is correct |
46 |
Correct |
2 ms |
9564 KB |
Output is correct |
47 |
Correct |
2 ms |
9564 KB |
Output is correct |
48 |
Correct |
3 ms |
9560 KB |
Output is correct |
49 |
Correct |
2 ms |
9564 KB |
Output is correct |
50 |
Correct |
2 ms |
9564 KB |
Output is correct |
51 |
Correct |
2 ms |
9564 KB |
Output is correct |
52 |
Correct |
3 ms |
9564 KB |
Output is correct |
53 |
Correct |
2 ms |
9564 KB |
Output is correct |
54 |
Correct |
2 ms |
9564 KB |
Output is correct |
55 |
Correct |
2 ms |
9564 KB |
Output is correct |
56 |
Correct |
2 ms |
9564 KB |
Output is correct |
57 |
Correct |
120 ms |
24404 KB |
Output is correct |
58 |
Correct |
68 ms |
24404 KB |
Output is correct |
59 |
Correct |
74 ms |
24584 KB |
Output is correct |
60 |
Correct |
74 ms |
24240 KB |
Output is correct |
61 |
Correct |
73 ms |
24332 KB |
Output is correct |
62 |
Correct |
82 ms |
24460 KB |
Output is correct |
63 |
Correct |
98 ms |
24188 KB |
Output is correct |
64 |
Correct |
94 ms |
24236 KB |
Output is correct |
65 |
Correct |
75 ms |
24404 KB |
Output is correct |
66 |
Correct |
71 ms |
24400 KB |
Output is correct |
67 |
Correct |
69 ms |
24376 KB |
Output is correct |
68 |
Correct |
70 ms |
24400 KB |
Output is correct |
69 |
Correct |
74 ms |
24808 KB |
Output is correct |
70 |
Correct |
71 ms |
24588 KB |
Output is correct |
71 |
Correct |
2 ms |
9564 KB |
Output is correct |
72 |
Correct |
6 ms |
9952 KB |
Output is correct |
73 |
Correct |
5 ms |
10076 KB |
Output is correct |
74 |
Correct |
3 ms |
10076 KB |
Output is correct |
75 |
Correct |
5 ms |
9956 KB |
Output is correct |
76 |
Correct |
5 ms |
9888 KB |
Output is correct |
77 |
Correct |
4 ms |
10076 KB |
Output is correct |
78 |
Correct |
4 ms |
10072 KB |
Output is correct |
79 |
Correct |
4 ms |
10076 KB |
Output is correct |
80 |
Correct |
73 ms |
24404 KB |
Output is correct |
81 |
Correct |
69 ms |
24404 KB |
Output is correct |
82 |
Correct |
98 ms |
24568 KB |
Output is correct |
83 |
Correct |
71 ms |
24380 KB |
Output is correct |
84 |
Correct |
3 ms |
10072 KB |
Output is correct |
85 |
Correct |
3 ms |
9924 KB |
Output is correct |
86 |
Correct |
3 ms |
9816 KB |
Output is correct |
87 |
Correct |
4 ms |
9820 KB |
Output is correct |
88 |
Correct |
4 ms |
9816 KB |
Output is correct |
89 |
Correct |
3 ms |
9816 KB |
Output is correct |
90 |
Correct |
4 ms |
9820 KB |
Output is correct |
91 |
Correct |
3 ms |
10076 KB |
Output is correct |
92 |
Correct |
4 ms |
10076 KB |
Output is correct |
93 |
Correct |
3 ms |
9820 KB |
Output is correct |
94 |
Correct |
2 ms |
9564 KB |
Output is correct |
95 |
Correct |
2 ms |
9564 KB |
Output is correct |
96 |
Correct |
2 ms |
9656 KB |
Output is correct |
97 |
Correct |
2 ms |
9564 KB |
Output is correct |
98 |
Correct |
2 ms |
9564 KB |
Output is correct |
99 |
Correct |
2 ms |
9564 KB |
Output is correct |
100 |
Correct |
2 ms |
9564 KB |
Output is correct |
101 |
Correct |
2 ms |
9564 KB |
Output is correct |
102 |
Correct |
2 ms |
9564 KB |
Output is correct |
103 |
Correct |
3 ms |
9564 KB |
Output is correct |
104 |
Correct |
7 ms |
11356 KB |
Output is correct |
105 |
Correct |
13 ms |
13760 KB |
Output is correct |
106 |
Correct |
3 ms |
9564 KB |
Output is correct |
107 |
Correct |
33 ms |
17372 KB |
Output is correct |
108 |
Correct |
45 ms |
20792 KB |
Output is correct |
109 |
Correct |
2 ms |
9564 KB |
Output is correct |
110 |
Correct |
54 ms |
23344 KB |
Output is correct |
111 |
Correct |
81 ms |
25488 KB |
Output is correct |
112 |
Correct |
3 ms |
9820 KB |
Output is correct |
113 |
Correct |
111 ms |
34644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
17636 KB |
Output is correct |
2 |
Incorrect |
26 ms |
17880 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
9564 KB |
Output is correct |
2 |
Correct |
3 ms |
9564 KB |
Output is correct |
3 |
Correct |
2 ms |
9560 KB |
Output is correct |
4 |
Correct |
2 ms |
9564 KB |
Output is correct |
5 |
Correct |
3 ms |
9716 KB |
Output is correct |
6 |
Correct |
3 ms |
9564 KB |
Output is correct |
7 |
Correct |
2 ms |
9564 KB |
Output is correct |
8 |
Correct |
3 ms |
9560 KB |
Output is correct |
9 |
Correct |
2 ms |
9564 KB |
Output is correct |
10 |
Correct |
2 ms |
9564 KB |
Output is correct |
11 |
Correct |
3 ms |
9564 KB |
Output is correct |
12 |
Correct |
2 ms |
9564 KB |
Output is correct |
13 |
Correct |
2 ms |
9560 KB |
Output is correct |
14 |
Correct |
3 ms |
9564 KB |
Output is correct |
15 |
Correct |
2 ms |
9564 KB |
Output is correct |
16 |
Correct |
2 ms |
9564 KB |
Output is correct |
17 |
Correct |
2 ms |
9664 KB |
Output is correct |
18 |
Correct |
2 ms |
9632 KB |
Output is correct |
19 |
Correct |
3 ms |
9564 KB |
Output is correct |
20 |
Correct |
2 ms |
9636 KB |
Output is correct |
21 |
Correct |
2 ms |
9560 KB |
Output is correct |
22 |
Correct |
3 ms |
9560 KB |
Output is correct |
23 |
Correct |
2 ms |
9644 KB |
Output is correct |
24 |
Correct |
2 ms |
9564 KB |
Output is correct |
25 |
Correct |
2 ms |
9564 KB |
Output is correct |
26 |
Correct |
2 ms |
9564 KB |
Output is correct |
27 |
Correct |
3 ms |
9820 KB |
Output is correct |
28 |
Correct |
4 ms |
9820 KB |
Output is correct |
29 |
Correct |
3 ms |
9560 KB |
Output is correct |
30 |
Correct |
3 ms |
9820 KB |
Output is correct |
31 |
Correct |
3 ms |
9820 KB |
Output is correct |
32 |
Incorrect |
5 ms |
9560 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
26708 KB |
Output is correct |
2 |
Correct |
90 ms |
26172 KB |
Output is correct |
3 |
Correct |
39 ms |
22864 KB |
Output is correct |
4 |
Correct |
10 ms |
12124 KB |
Output is correct |
5 |
Correct |
10 ms |
11100 KB |
Output is correct |
6 |
Correct |
18 ms |
13404 KB |
Output is correct |
7 |
Correct |
3 ms |
9560 KB |
Output is correct |
8 |
Correct |
24 ms |
16732 KB |
Output is correct |
9 |
Correct |
36 ms |
20316 KB |
Output is correct |
10 |
Correct |
2 ms |
9564 KB |
Output is correct |
11 |
Correct |
59 ms |
23124 KB |
Output is correct |
12 |
Correct |
106 ms |
25424 KB |
Output is correct |
13 |
Correct |
3 ms |
9816 KB |
Output is correct |
14 |
Correct |
2 ms |
9564 KB |
Output is correct |
15 |
Correct |
3 ms |
9564 KB |
Output is correct |
16 |
Correct |
2 ms |
9560 KB |
Output is correct |
17 |
Correct |
2 ms |
9564 KB |
Output is correct |
18 |
Correct |
3 ms |
9716 KB |
Output is correct |
19 |
Correct |
3 ms |
9564 KB |
Output is correct |
20 |
Correct |
2 ms |
9564 KB |
Output is correct |
21 |
Correct |
3 ms |
9560 KB |
Output is correct |
22 |
Correct |
2 ms |
9564 KB |
Output is correct |
23 |
Correct |
2 ms |
9564 KB |
Output is correct |
24 |
Correct |
3 ms |
9564 KB |
Output is correct |
25 |
Correct |
2 ms |
9564 KB |
Output is correct |
26 |
Correct |
2 ms |
9560 KB |
Output is correct |
27 |
Correct |
3 ms |
9564 KB |
Output is correct |
28 |
Correct |
2 ms |
9564 KB |
Output is correct |
29 |
Correct |
2 ms |
9564 KB |
Output is correct |
30 |
Correct |
2 ms |
9664 KB |
Output is correct |
31 |
Correct |
2 ms |
9632 KB |
Output is correct |
32 |
Correct |
3 ms |
9564 KB |
Output is correct |
33 |
Correct |
2 ms |
9636 KB |
Output is correct |
34 |
Correct |
2 ms |
9560 KB |
Output is correct |
35 |
Correct |
3 ms |
9560 KB |
Output is correct |
36 |
Correct |
2 ms |
9644 KB |
Output is correct |
37 |
Correct |
2 ms |
9564 KB |
Output is correct |
38 |
Correct |
2 ms |
9564 KB |
Output is correct |
39 |
Correct |
101 ms |
27812 KB |
Output is correct |
40 |
Correct |
68 ms |
27380 KB |
Output is correct |
41 |
Correct |
49 ms |
23636 KB |
Output is correct |
42 |
Correct |
8 ms |
12120 KB |
Output is correct |
43 |
Correct |
2 ms |
9564 KB |
Output is correct |
44 |
Correct |
2 ms |
9564 KB |
Output is correct |
45 |
Correct |
3 ms |
9560 KB |
Output is correct |
46 |
Correct |
2 ms |
9564 KB |
Output is correct |
47 |
Correct |
2 ms |
9564 KB |
Output is correct |
48 |
Correct |
3 ms |
9560 KB |
Output is correct |
49 |
Correct |
2 ms |
9564 KB |
Output is correct |
50 |
Correct |
2 ms |
9564 KB |
Output is correct |
51 |
Correct |
2 ms |
9564 KB |
Output is correct |
52 |
Correct |
3 ms |
9564 KB |
Output is correct |
53 |
Correct |
2 ms |
9564 KB |
Output is correct |
54 |
Correct |
2 ms |
9564 KB |
Output is correct |
55 |
Correct |
2 ms |
9564 KB |
Output is correct |
56 |
Correct |
2 ms |
9564 KB |
Output is correct |
57 |
Correct |
120 ms |
24404 KB |
Output is correct |
58 |
Correct |
68 ms |
24404 KB |
Output is correct |
59 |
Correct |
74 ms |
24584 KB |
Output is correct |
60 |
Correct |
74 ms |
24240 KB |
Output is correct |
61 |
Correct |
73 ms |
24332 KB |
Output is correct |
62 |
Correct |
82 ms |
24460 KB |
Output is correct |
63 |
Correct |
98 ms |
24188 KB |
Output is correct |
64 |
Correct |
94 ms |
24236 KB |
Output is correct |
65 |
Correct |
75 ms |
24404 KB |
Output is correct |
66 |
Correct |
71 ms |
24400 KB |
Output is correct |
67 |
Correct |
69 ms |
24376 KB |
Output is correct |
68 |
Correct |
70 ms |
24400 KB |
Output is correct |
69 |
Correct |
74 ms |
24808 KB |
Output is correct |
70 |
Correct |
71 ms |
24588 KB |
Output is correct |
71 |
Correct |
2 ms |
9564 KB |
Output is correct |
72 |
Correct |
6 ms |
9952 KB |
Output is correct |
73 |
Correct |
5 ms |
10076 KB |
Output is correct |
74 |
Correct |
3 ms |
10076 KB |
Output is correct |
75 |
Correct |
5 ms |
9956 KB |
Output is correct |
76 |
Correct |
5 ms |
9888 KB |
Output is correct |
77 |
Correct |
4 ms |
10076 KB |
Output is correct |
78 |
Correct |
4 ms |
10072 KB |
Output is correct |
79 |
Correct |
4 ms |
10076 KB |
Output is correct |
80 |
Correct |
73 ms |
24404 KB |
Output is correct |
81 |
Correct |
69 ms |
24404 KB |
Output is correct |
82 |
Correct |
98 ms |
24568 KB |
Output is correct |
83 |
Correct |
71 ms |
24380 KB |
Output is correct |
84 |
Correct |
3 ms |
10072 KB |
Output is correct |
85 |
Correct |
3 ms |
9924 KB |
Output is correct |
86 |
Correct |
3 ms |
9816 KB |
Output is correct |
87 |
Correct |
4 ms |
9820 KB |
Output is correct |
88 |
Correct |
4 ms |
9816 KB |
Output is correct |
89 |
Correct |
3 ms |
9816 KB |
Output is correct |
90 |
Correct |
4 ms |
9820 KB |
Output is correct |
91 |
Correct |
3 ms |
10076 KB |
Output is correct |
92 |
Correct |
4 ms |
10076 KB |
Output is correct |
93 |
Correct |
3 ms |
9820 KB |
Output is correct |
94 |
Correct |
2 ms |
9564 KB |
Output is correct |
95 |
Correct |
2 ms |
9564 KB |
Output is correct |
96 |
Correct |
2 ms |
9656 KB |
Output is correct |
97 |
Correct |
2 ms |
9564 KB |
Output is correct |
98 |
Correct |
2 ms |
9564 KB |
Output is correct |
99 |
Correct |
2 ms |
9564 KB |
Output is correct |
100 |
Correct |
2 ms |
9564 KB |
Output is correct |
101 |
Correct |
2 ms |
9564 KB |
Output is correct |
102 |
Correct |
2 ms |
9564 KB |
Output is correct |
103 |
Correct |
3 ms |
9564 KB |
Output is correct |
104 |
Correct |
7 ms |
11356 KB |
Output is correct |
105 |
Correct |
13 ms |
13760 KB |
Output is correct |
106 |
Correct |
3 ms |
9564 KB |
Output is correct |
107 |
Correct |
33 ms |
17372 KB |
Output is correct |
108 |
Correct |
45 ms |
20792 KB |
Output is correct |
109 |
Correct |
2 ms |
9564 KB |
Output is correct |
110 |
Correct |
54 ms |
23344 KB |
Output is correct |
111 |
Correct |
81 ms |
25488 KB |
Output is correct |
112 |
Correct |
3 ms |
9820 KB |
Output is correct |
113 |
Correct |
111 ms |
34644 KB |
Output is correct |
114 |
Correct |
27 ms |
17636 KB |
Output is correct |
115 |
Incorrect |
26 ms |
17880 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |