# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
589222 | 2022-07-04T10:45:00 Z | Vanilla | Dreaming (IOI13_dreaming) | C++17 | 120 ms | 34256 KB |
#include <bits/stdc++.h> #include "dreaming.h" typedef long long int64; using namespace std; const int maxn = 1e5 + 2; int64 dp[maxn]; // dp[i] -> max dist to leaf in subtree i vector <pair <int64, int64> > ad [maxn]; vector <int64> a; bitset <maxn> vis; int travelTime(int N, int M, int L, int A[], int B[], int T[]) { for (int i = 0; i < M; i++){ ad[A[i]].push_back({B[i], T[i]}); ad[B[i]].push_back({A[i], T[i]}); } int64 rs = 0; for (int i = 0; i < N; i++){ if (!vis[i]) { auto process = [&] () { int64 diam = 0, mxdist = 1e18; auto dfs = [&] (int u, auto &&dfs) -> void { vis[u] = 1; for (auto &[v, cost]: ad[u]) { if (!vis[v]) { dfs(v, dfs); dp[u] = max(dp[u], dp[v] + cost); } } }; dfs(i, dfs); auto sum = [&] (int u, int p, auto &&sum) -> void { vector <int64> sm; for (auto &[v, cost]: ad[u]) { if (v == p) continue; sm.push_back(dp[v] + cost); sum(v, u, sum); } int64 ret = 0; sort(sm.begin(), sm.end(), greater <int64> ()); for (int i = 0; i < min(2, (int) sm.size()); i++) ret+=sm[i]; diam = max(diam, ret); return; }; sum(i, -1, sum); auto dist = [&] (int u, int p, int64 pans, auto &&dist) -> void { vector <int64> pref, suff; for (auto &[v, cost]: ad[u]) { if (v == p) continue; pref.push_back(dp[v] + cost); suff.push_back(dp[v] + cost); } for (int i = 1; i < pref.size(); i++) pref[i] = max(pref[i-1], pref[i]); for (int i = suff.size() - 2; i >= 0; i--) suff[i] = max(suff[i + 1], suff[i]); mxdist = min(mxdist, max(pans, suff.empty() ? 0: suff[0])); // cout << u << " " << max(pans, suff.empty() ? 0: suff[0]) << "\n"; int idx = 0; for (auto &[v, cost]: ad[u]) { if (v == p) continue; int64 p1 = (idx == 0 ? -1e9 : pref[idx-1]); int64 p2 = (idx == suff.size() - 1 ? -1e9: suff[idx + 1]); dist(v, u, max({p1, p2, pans}) + cost, dist); idx++; } }; dist(i, -1, 0, dist); rs = max(rs, diam); a.push_back(mxdist); // cout << i << " " << diam << " " << mxdist << "\n"; }; process(); } } sort(a.begin(), a.end(), greater <int64> ()); for (int64 i = 1; i < a.size(); i++){ rs = max(rs, a[i] + a[i - 1] + i * L); } return rs; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 64 ms | 21456 KB | Output is correct |
2 | Correct | 64 ms | 20420 KB | Output is correct |
3 | Correct | 44 ms | 19532 KB | Output is correct |
4 | Correct | 9 ms | 5332 KB | Output is correct |
5 | Correct | 8 ms | 3928 KB | Output is correct |
6 | Correct | 17 ms | 6736 KB | Output is correct |
7 | Correct | 1 ms | 2644 KB | Output is correct |
8 | Correct | 54 ms | 10188 KB | Output is correct |
9 | Correct | 48 ms | 15740 KB | Output is correct |
10 | Correct | 2 ms | 2772 KB | Output is correct |
11 | Correct | 74 ms | 15720 KB | Output is correct |
12 | Correct | 83 ms | 18560 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 | 1 ms | 2644 KB | Output is correct |
3 | Correct | 2 ms | 2644 KB | Output is correct |
4 | Correct | 1 ms | 2644 KB | Output is correct |
5 | Correct | 1 ms | 2644 KB | Output is correct |
6 | Correct | 1 ms | 2644 KB | Output is correct |
7 | Correct | 1 ms | 2644 KB | Output is correct |
8 | Correct | 1 ms | 2644 KB | Output is correct |
9 | Correct | 2 ms | 2644 KB | Output is correct |
10 | Correct | 2 ms | 2644 KB | Output is correct |
11 | Correct | 1 ms | 2644 KB | Output is correct |
12 | Correct | 2 ms | 2644 KB | Output is correct |
13 | Correct | 3 ms | 2644 KB | Output is correct |
14 | Correct | 3 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 | 1 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 | 2 ms | 2644 KB | Output is correct |
23 | Correct | 2 ms | 2644 KB | Output is correct |
24 | Correct | 1 ms | 2644 KB | Output is correct |
25 | Correct | 1 ms | 2644 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 64 ms | 21456 KB | Output is correct |
2 | Correct | 64 ms | 20420 KB | Output is correct |
3 | Correct | 44 ms | 19532 KB | Output is correct |
4 | Correct | 9 ms | 5332 KB | Output is correct |
5 | Correct | 8 ms | 3928 KB | Output is correct |
6 | Correct | 17 ms | 6736 KB | Output is correct |
7 | Correct | 1 ms | 2644 KB | Output is correct |
8 | Correct | 54 ms | 10188 KB | Output is correct |
9 | Correct | 48 ms | 15740 KB | Output is correct |
10 | Correct | 2 ms | 2772 KB | Output is correct |
11 | Correct | 74 ms | 15720 KB | Output is correct |
12 | Correct | 83 ms | 18560 KB | Output is correct |
13 | Correct | 2 ms | 2772 KB | Output is correct |
14 | Correct | 2 ms | 2644 KB | Output is correct |
15 | Correct | 1 ms | 2644 KB | Output is correct |
16 | Correct | 2 ms | 2644 KB | Output is correct |
17 | Correct | 1 ms | 2644 KB | Output is correct |
18 | Correct | 1 ms | 2644 KB | Output is correct |
19 | Correct | 1 ms | 2644 KB | Output is correct |
20 | Correct | 1 ms | 2644 KB | Output is correct |
21 | Correct | 1 ms | 2644 KB | Output is correct |
22 | Correct | 2 ms | 2644 KB | Output is correct |
23 | Correct | 2 ms | 2644 KB | Output is correct |
24 | Correct | 1 ms | 2644 KB | Output is correct |
25 | Correct | 2 ms | 2644 KB | Output is correct |
26 | Correct | 3 ms | 2644 KB | Output is correct |
27 | Correct | 3 ms | 2644 KB | Output is correct |
28 | Correct | 2 ms | 2644 KB | Output is correct |
29 | Correct | 1 ms | 2644 KB | Output is correct |
30 | Correct | 1 ms | 2644 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 | 2644 KB | Output is correct |
37 | Correct | 1 ms | 2644 KB | Output is correct |
38 | Correct | 1 ms | 2644 KB | Output is correct |
39 | Correct | 64 ms | 21248 KB | Output is correct |
40 | Correct | 70 ms | 20376 KB | Output is correct |
41 | Correct | 43 ms | 19448 KB | Output is correct |
42 | Correct | 9 ms | 5244 KB | Output is correct |
43 | Correct | 2 ms | 2644 KB | Output is correct |
44 | Correct | 1 ms | 2644 KB | Output is correct |
45 | Correct | 1 ms | 2644 KB | Output is correct |
46 | Correct | 1 ms | 2644 KB | Output is correct |
47 | Correct | 3 ms | 2644 KB | Output is correct |
48 | Correct | 1 ms | 2644 KB | Output is correct |
49 | Correct | 1 ms | 2644 KB | Output is correct |
50 | Correct | 1 ms | 2644 KB | Output is correct |
51 | Correct | 1 ms | 2644 KB | Output is correct |
52 | Correct | 2 ms | 2644 KB | Output is correct |
53 | Correct | 1 ms | 2644 KB | Output is correct |
54 | Correct | 1 ms | 2644 KB | Output is correct |
55 | Correct | 1 ms | 2644 KB | Output is correct |
56 | Correct | 2 ms | 2644 KB | Output is correct |
57 | Correct | 83 ms | 10572 KB | Output is correct |
58 | Correct | 111 ms | 10488 KB | Output is correct |
59 | Correct | 93 ms | 10284 KB | Output is correct |
60 | Correct | 80 ms | 10284 KB | Output is correct |
61 | Correct | 85 ms | 10040 KB | Output is correct |
62 | Correct | 80 ms | 10028 KB | Output is correct |
63 | Correct | 76 ms | 9772 KB | Output is correct |
64 | Correct | 96 ms | 9760 KB | Output is correct |
65 | Correct | 97 ms | 9676 KB | Output is correct |
66 | Correct | 73 ms | 9664 KB | Output is correct |
67 | Correct | 85 ms | 10432 KB | Output is correct |
68 | Correct | 82 ms | 10432 KB | Output is correct |
69 | Correct | 81 ms | 10400 KB | Output is correct |
70 | Correct | 83 ms | 10316 KB | Output is correct |
71 | Correct | 1 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 | 4 ms | 3028 KB | Output is correct |
75 | Correct | 5 ms | 2904 KB | Output is correct |
76 | Correct | 4 ms | 2900 KB | Output is correct |
77 | Correct | 4 ms | 2900 KB | Output is correct |
78 | Correct | 3 ms | 2900 KB | Output is correct |
79 | Correct | 3 ms | 2900 KB | Output is correct |
80 | Correct | 80 ms | 10296 KB | Output is correct |
81 | Correct | 75 ms | 10240 KB | Output is correct |
82 | Correct | 84 ms | 10056 KB | Output is correct |
83 | Correct | 92 ms | 10040 KB | Output is correct |
84 | Correct | 4 ms | 2820 KB | Output is correct |
85 | Correct | 2 ms | 2772 KB | Output is correct |
86 | Correct | 4 ms | 2772 KB | Output is correct |
87 | Correct | 4 ms | 2772 KB | Output is correct |
88 | Correct | 3 ms | 2772 KB | Output is correct |
89 | Correct | 2 ms | 2772 KB | Output is correct |
90 | Correct | 3 ms | 2772 KB | Output is correct |
91 | Correct | 3 ms | 2772 KB | Output is correct |
92 | Correct | 3 ms | 2772 KB | Output is correct |
93 | Correct | 3 ms | 2772 KB | Output is correct |
94 | Correct | 1 ms | 2644 KB | Output is correct |
95 | Correct | 1 ms | 2644 KB | Output is correct |
96 | Correct | 1 ms | 2644 KB | Output is correct |
97 | Correct | 1 ms | 2644 KB | Output is correct |
98 | Correct | 2 ms | 2644 KB | Output is correct |
99 | Correct | 1 ms | 2644 KB | Output is correct |
100 | Correct | 1 ms | 2676 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 | 7 ms | 3936 KB | Output is correct |
105 | Correct | 15 ms | 6780 KB | Output is correct |
106 | Correct | 2 ms | 2644 KB | Output is correct |
107 | Correct | 39 ms | 10188 KB | Output is correct |
108 | Correct | 60 ms | 15768 KB | Output is correct |
109 | Correct | 2 ms | 2772 KB | Output is correct |
110 | Correct | 71 ms | 15684 KB | Output is correct |
111 | Correct | 79 ms | 18500 KB | Output is correct |
112 | Correct | 2 ms | 2772 KB | Output is correct |
113 | Correct | 120 ms | 34256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 23 ms | 6352 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 | 1 ms | 2644 KB | Output is correct |
3 | Correct | 2 ms | 2644 KB | Output is correct |
4 | Correct | 1 ms | 2644 KB | Output is correct |
5 | Correct | 1 ms | 2644 KB | Output is correct |
6 | Correct | 1 ms | 2644 KB | Output is correct |
7 | Correct | 1 ms | 2644 KB | Output is correct |
8 | Correct | 1 ms | 2644 KB | Output is correct |
9 | Correct | 2 ms | 2644 KB | Output is correct |
10 | Correct | 2 ms | 2644 KB | Output is correct |
11 | Correct | 1 ms | 2644 KB | Output is correct |
12 | Correct | 2 ms | 2644 KB | Output is correct |
13 | Correct | 3 ms | 2644 KB | Output is correct |
14 | Correct | 3 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 | 1 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 | 2 ms | 2644 KB | Output is correct |
23 | Correct | 2 ms | 2644 KB | Output is correct |
24 | Correct | 1 ms | 2644 KB | Output is correct |
25 | Correct | 1 ms | 2644 KB | Output is correct |
26 | Correct | 2 ms | 2644 KB | Output is correct |
27 | Incorrect | 4 ms | 2772 KB | Output isn't correct |
28 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 64 ms | 21456 KB | Output is correct |
2 | Correct | 64 ms | 20420 KB | Output is correct |
3 | Correct | 44 ms | 19532 KB | Output is correct |
4 | Correct | 9 ms | 5332 KB | Output is correct |
5 | Correct | 8 ms | 3928 KB | Output is correct |
6 | Correct | 17 ms | 6736 KB | Output is correct |
7 | Correct | 1 ms | 2644 KB | Output is correct |
8 | Correct | 54 ms | 10188 KB | Output is correct |
9 | Correct | 48 ms | 15740 KB | Output is correct |
10 | Correct | 2 ms | 2772 KB | Output is correct |
11 | Correct | 74 ms | 15720 KB | Output is correct |
12 | Correct | 83 ms | 18560 KB | Output is correct |
13 | Correct | 2 ms | 2772 KB | Output is correct |
14 | Correct | 2 ms | 2644 KB | Output is correct |
15 | Correct | 1 ms | 2644 KB | Output is correct |
16 | Correct | 2 ms | 2644 KB | Output is correct |
17 | Correct | 1 ms | 2644 KB | Output is correct |
18 | Correct | 1 ms | 2644 KB | Output is correct |
19 | Correct | 1 ms | 2644 KB | Output is correct |
20 | Correct | 1 ms | 2644 KB | Output is correct |
21 | Correct | 1 ms | 2644 KB | Output is correct |
22 | Correct | 2 ms | 2644 KB | Output is correct |
23 | Correct | 2 ms | 2644 KB | Output is correct |
24 | Correct | 1 ms | 2644 KB | Output is correct |
25 | Correct | 2 ms | 2644 KB | Output is correct |
26 | Correct | 3 ms | 2644 KB | Output is correct |
27 | Correct | 3 ms | 2644 KB | Output is correct |
28 | Correct | 2 ms | 2644 KB | Output is correct |
29 | Correct | 1 ms | 2644 KB | Output is correct |
30 | Correct | 1 ms | 2644 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 | 2644 KB | Output is correct |
37 | Correct | 1 ms | 2644 KB | Output is correct |
38 | Correct | 1 ms | 2644 KB | Output is correct |
39 | Correct | 64 ms | 21248 KB | Output is correct |
40 | Correct | 70 ms | 20376 KB | Output is correct |
41 | Correct | 43 ms | 19448 KB | Output is correct |
42 | Correct | 9 ms | 5244 KB | Output is correct |
43 | Correct | 2 ms | 2644 KB | Output is correct |
44 | Correct | 1 ms | 2644 KB | Output is correct |
45 | Correct | 1 ms | 2644 KB | Output is correct |
46 | Correct | 1 ms | 2644 KB | Output is correct |
47 | Correct | 3 ms | 2644 KB | Output is correct |
48 | Correct | 1 ms | 2644 KB | Output is correct |
49 | Correct | 1 ms | 2644 KB | Output is correct |
50 | Correct | 1 ms | 2644 KB | Output is correct |
51 | Correct | 1 ms | 2644 KB | Output is correct |
52 | Correct | 2 ms | 2644 KB | Output is correct |
53 | Correct | 1 ms | 2644 KB | Output is correct |
54 | Correct | 1 ms | 2644 KB | Output is correct |
55 | Correct | 1 ms | 2644 KB | Output is correct |
56 | Correct | 2 ms | 2644 KB | Output is correct |
57 | Correct | 83 ms | 10572 KB | Output is correct |
58 | Correct | 111 ms | 10488 KB | Output is correct |
59 | Correct | 93 ms | 10284 KB | Output is correct |
60 | Correct | 80 ms | 10284 KB | Output is correct |
61 | Correct | 85 ms | 10040 KB | Output is correct |
62 | Correct | 80 ms | 10028 KB | Output is correct |
63 | Correct | 76 ms | 9772 KB | Output is correct |
64 | Correct | 96 ms | 9760 KB | Output is correct |
65 | Correct | 97 ms | 9676 KB | Output is correct |
66 | Correct | 73 ms | 9664 KB | Output is correct |
67 | Correct | 85 ms | 10432 KB | Output is correct |
68 | Correct | 82 ms | 10432 KB | Output is correct |
69 | Correct | 81 ms | 10400 KB | Output is correct |
70 | Correct | 83 ms | 10316 KB | Output is correct |
71 | Correct | 1 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 | 4 ms | 3028 KB | Output is correct |
75 | Correct | 5 ms | 2904 KB | Output is correct |
76 | Correct | 4 ms | 2900 KB | Output is correct |
77 | Correct | 4 ms | 2900 KB | Output is correct |
78 | Correct | 3 ms | 2900 KB | Output is correct |
79 | Correct | 3 ms | 2900 KB | Output is correct |
80 | Correct | 80 ms | 10296 KB | Output is correct |
81 | Correct | 75 ms | 10240 KB | Output is correct |
82 | Correct | 84 ms | 10056 KB | Output is correct |
83 | Correct | 92 ms | 10040 KB | Output is correct |
84 | Correct | 4 ms | 2820 KB | Output is correct |
85 | Correct | 2 ms | 2772 KB | Output is correct |
86 | Correct | 4 ms | 2772 KB | Output is correct |
87 | Correct | 4 ms | 2772 KB | Output is correct |
88 | Correct | 3 ms | 2772 KB | Output is correct |
89 | Correct | 2 ms | 2772 KB | Output is correct |
90 | Correct | 3 ms | 2772 KB | Output is correct |
91 | Correct | 3 ms | 2772 KB | Output is correct |
92 | Correct | 3 ms | 2772 KB | Output is correct |
93 | Correct | 3 ms | 2772 KB | Output is correct |
94 | Correct | 1 ms | 2644 KB | Output is correct |
95 | Correct | 1 ms | 2644 KB | Output is correct |
96 | Correct | 1 ms | 2644 KB | Output is correct |
97 | Correct | 1 ms | 2644 KB | Output is correct |
98 | Correct | 2 ms | 2644 KB | Output is correct |
99 | Correct | 1 ms | 2644 KB | Output is correct |
100 | Correct | 1 ms | 2676 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 | 7 ms | 3936 KB | Output is correct |
105 | Correct | 15 ms | 6780 KB | Output is correct |
106 | Correct | 2 ms | 2644 KB | Output is correct |
107 | Correct | 39 ms | 10188 KB | Output is correct |
108 | Correct | 60 ms | 15768 KB | Output is correct |
109 | Correct | 2 ms | 2772 KB | Output is correct |
110 | Correct | 71 ms | 15684 KB | Output is correct |
111 | Correct | 79 ms | 18500 KB | Output is correct |
112 | Correct | 2 ms | 2772 KB | Output is correct |
113 | Correct | 120 ms | 34256 KB | Output is correct |
114 | Incorrect | 23 ms | 6352 KB | Output isn't correct |
115 | Halted | 0 ms | 0 KB | - |