Submission #589209

# Submission time Handle Problem Language Result Execution time Memory
589209 2022-07-04T10:34:08 Z Vanilla Dreaming (IOI13_dreaming) C++17
47 / 100
168 ms 35864 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> ());
    if (a.size() == 2) rs = max(rs, a[0] + a[1] + L);
    else rs = max({rs, a[0] + a[1] + L, a[1] + a[2] + 2 * L});
    return rs;
}

Compilation message

dreaming.cpp: In lambda function:
dreaming.cpp:53:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |                     for (int i = 1; i < pref.size(); i++) pref[i] = max(pref[i-1], pref[i]);
      |                                     ~~^~~~~~~~~~~~~
dreaming.cpp: In instantiation of 'travelTime(int, int, int, int*, int*, int*)::<lambda()>::<lambda(int, int, int64, auto:25&&)> [with auto:25 = travelTime(int, int, int, int*, int*, int*)::<lambda()>::<lambda(int, int, int64, auto:25&&)>&; int64 = long long int]':
dreaming.cpp:65:39:   required from here
dreaming.cpp:53:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
dreaming.cpp:61:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |                         int64 p2 = (idx == suff.size() - 1 ? -1e9: suff[idx + 1]);
      |                                     ~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 78 ms 22592 KB Output is correct
2 Correct 73 ms 21544 KB Output is correct
3 Correct 51 ms 20436 KB Output is correct
4 Correct 13 ms 5460 KB Output is correct
5 Correct 9 ms 4144 KB Output is correct
6 Correct 23 ms 7108 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 37 ms 10740 KB Output is correct
9 Correct 52 ms 16444 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 76 ms 16824 KB Output is correct
12 Correct 93 ms 19648 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 2644 KB Output is correct
5 Correct 2 ms 2664 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 2 ms 2664 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2664 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2664 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 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 2664 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 2 ms 2580 KB Output is correct
25 Correct 2 ms 2660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 22592 KB Output is correct
2 Correct 73 ms 21544 KB Output is correct
3 Correct 51 ms 20436 KB Output is correct
4 Correct 13 ms 5460 KB Output is correct
5 Correct 9 ms 4144 KB Output is correct
6 Correct 23 ms 7108 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 37 ms 10740 KB Output is correct
9 Correct 52 ms 16444 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 76 ms 16824 KB Output is correct
12 Correct 93 ms 19648 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 2644 KB Output is correct
18 Correct 2 ms 2664 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 2664 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 Correct 2 ms 2664 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 2644 KB Output is correct
30 Correct 2 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 2664 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 2 ms 2580 KB Output is correct
38 Correct 2 ms 2660 KB Output is correct
39 Correct 66 ms 22516 KB Output is correct
40 Correct 68 ms 21728 KB Output is correct
41 Correct 56 ms 20348 KB Output is correct
42 Correct 14 ms 5536 KB Output is correct
43 Correct 3 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 1 ms 2644 KB Output is correct
48 Correct 2 ms 2644 KB Output is correct
49 Correct 2 ms 2644 KB Output is correct
50 Correct 2 ms 2632 KB Output is correct
51 Correct 2 ms 2644 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 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 80 ms 11848 KB Output is correct
58 Correct 110 ms 11844 KB Output is correct
59 Correct 121 ms 11656 KB Output is correct
60 Correct 92 ms 11696 KB Output is correct
61 Correct 86 ms 11584 KB Output is correct
62 Correct 89 ms 11564 KB Output is correct
63 Correct 83 ms 11080 KB Output is correct
64 Correct 132 ms 11112 KB Output is correct
65 Correct 97 ms 11408 KB Output is correct
66 Correct 113 ms 11384 KB Output is correct
67 Correct 99 ms 11784 KB Output is correct
68 Correct 112 ms 11772 KB Output is correct
69 Correct 130 ms 12028 KB Output is correct
70 Correct 89 ms 11896 KB Output is correct
71 Correct 2 ms 2644 KB Output is correct
72 Correct 3 ms 2900 KB Output is correct
73 Correct 3 ms 2900 KB Output is correct
74 Correct 3 ms 2900 KB Output is correct
75 Correct 3 ms 2900 KB Output is correct
76 Correct 3 ms 2900 KB Output is correct
77 Correct 6 ms 2904 KB Output is correct
78 Correct 4 ms 2900 KB Output is correct
79 Correct 3 ms 2900 KB Output is correct
80 Correct 97 ms 11648 KB Output is correct
81 Correct 110 ms 11612 KB Output is correct
82 Correct 91 ms 11576 KB Output is correct
83 Correct 76 ms 11576 KB Output is correct
84 Correct 3 ms 2800 KB Output is correct
85 Correct 3 ms 2804 KB Output is correct
86 Correct 4 ms 2804 KB Output is correct
87 Correct 5 ms 2900 KB Output is correct
88 Correct 4 ms 2900 KB Output is correct
89 Correct 4 ms 2804 KB Output is correct
90 Correct 5 ms 2900 KB Output is correct
91 Correct 4 ms 2900 KB Output is correct
92 Correct 3 ms 2900 KB Output is correct
93 Correct 4 ms 2848 KB Output is correct
94 Correct 2 ms 2644 KB Output is correct
95 Correct 6 ms 2668 KB Output is correct
96 Correct 3 ms 2664 KB Output is correct
97 Correct 2 ms 2644 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 2660 KB Output is correct
101 Correct 2 ms 2644 KB Output is correct
102 Correct 3 ms 2664 KB Output is correct
103 Correct 3 ms 2644 KB Output is correct
104 Correct 12 ms 4144 KB Output is correct
105 Correct 28 ms 7020 KB Output is correct
106 Correct 3 ms 2644 KB Output is correct
107 Correct 46 ms 10716 KB Output is correct
108 Correct 61 ms 16460 KB Output is correct
109 Correct 3 ms 2796 KB Output is correct
110 Correct 71 ms 16872 KB Output is correct
111 Correct 119 ms 19636 KB Output is correct
112 Correct 3 ms 2772 KB Output is correct
113 Correct 168 ms 35864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 6632 KB Output is correct
2 Correct 30 ms 6704 KB Output is correct
3 Correct 28 ms 6732 KB Output is correct
4 Correct 29 ms 6660 KB Output is correct
5 Correct 33 ms 6644 KB Output is correct
6 Correct 33 ms 7428 KB Output is correct
7 Correct 34 ms 6904 KB Output is correct
8 Correct 32 ms 6612 KB Output is correct
9 Correct 33 ms 6576 KB Output is correct
10 Correct 43 ms 6844 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 8 ms 4300 KB Output is correct
13 Correct 6 ms 4300 KB Output is correct
14 Correct 6 ms 4172 KB Output is correct
15 Correct 6 ms 4300 KB Output is correct
16 Correct 6 ms 4240 KB Output is correct
17 Correct 6 ms 3916 KB Output is correct
18 Correct 7 ms 4300 KB Output is correct
19 Correct 7 ms 4168 KB Output is correct
20 Incorrect 2 ms 2644 KB Output isn't correct
21 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 2644 KB Output is correct
5 Correct 2 ms 2664 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 2 ms 2664 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2664 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2664 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 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 2664 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 2 ms 2580 KB Output is correct
25 Correct 2 ms 2660 KB Output is correct
26 Correct 3 ms 2644 KB Output is correct
27 Correct 4 ms 2796 KB Output is correct
28 Correct 4 ms 2848 KB Output is correct
29 Correct 3 ms 2644 KB Output is correct
30 Correct 3 ms 2824 KB Output is correct
31 Correct 3 ms 2900 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 3 ms 2804 KB Output is correct
34 Correct 4 ms 2784 KB Output is correct
35 Correct 1 ms 2644 KB Output is correct
36 Correct 2 ms 2644 KB Output is correct
37 Correct 3 ms 2644 KB Output is correct
38 Correct 3 ms 2644 KB Output is correct
39 Correct 3 ms 2644 KB Output is correct
40 Correct 2 ms 2656 KB Output is correct
41 Correct 2 ms 2644 KB Output is correct
42 Correct 2 ms 2648 KB Output is correct
43 Correct 2 ms 2660 KB Output is correct
44 Correct 3 ms 2660 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 2644 KB Output is correct
49 Correct 2 ms 2664 KB Output is correct
50 Correct 3 ms 2644 KB Output is correct
51 Correct 2 ms 2600 KB Output is correct
52 Incorrect 2 ms 2644 KB Output isn't correct
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 78 ms 22592 KB Output is correct
2 Correct 73 ms 21544 KB Output is correct
3 Correct 51 ms 20436 KB Output is correct
4 Correct 13 ms 5460 KB Output is correct
5 Correct 9 ms 4144 KB Output is correct
6 Correct 23 ms 7108 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 37 ms 10740 KB Output is correct
9 Correct 52 ms 16444 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 76 ms 16824 KB Output is correct
12 Correct 93 ms 19648 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 2644 KB Output is correct
18 Correct 2 ms 2664 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 2664 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 Correct 2 ms 2664 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 2644 KB Output is correct
30 Correct 2 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 2664 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 2 ms 2580 KB Output is correct
38 Correct 2 ms 2660 KB Output is correct
39 Correct 66 ms 22516 KB Output is correct
40 Correct 68 ms 21728 KB Output is correct
41 Correct 56 ms 20348 KB Output is correct
42 Correct 14 ms 5536 KB Output is correct
43 Correct 3 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 1 ms 2644 KB Output is correct
48 Correct 2 ms 2644 KB Output is correct
49 Correct 2 ms 2644 KB Output is correct
50 Correct 2 ms 2632 KB Output is correct
51 Correct 2 ms 2644 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 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 80 ms 11848 KB Output is correct
58 Correct 110 ms 11844 KB Output is correct
59 Correct 121 ms 11656 KB Output is correct
60 Correct 92 ms 11696 KB Output is correct
61 Correct 86 ms 11584 KB Output is correct
62 Correct 89 ms 11564 KB Output is correct
63 Correct 83 ms 11080 KB Output is correct
64 Correct 132 ms 11112 KB Output is correct
65 Correct 97 ms 11408 KB Output is correct
66 Correct 113 ms 11384 KB Output is correct
67 Correct 99 ms 11784 KB Output is correct
68 Correct 112 ms 11772 KB Output is correct
69 Correct 130 ms 12028 KB Output is correct
70 Correct 89 ms 11896 KB Output is correct
71 Correct 2 ms 2644 KB Output is correct
72 Correct 3 ms 2900 KB Output is correct
73 Correct 3 ms 2900 KB Output is correct
74 Correct 3 ms 2900 KB Output is correct
75 Correct 3 ms 2900 KB Output is correct
76 Correct 3 ms 2900 KB Output is correct
77 Correct 6 ms 2904 KB Output is correct
78 Correct 4 ms 2900 KB Output is correct
79 Correct 3 ms 2900 KB Output is correct
80 Correct 97 ms 11648 KB Output is correct
81 Correct 110 ms 11612 KB Output is correct
82 Correct 91 ms 11576 KB Output is correct
83 Correct 76 ms 11576 KB Output is correct
84 Correct 3 ms 2800 KB Output is correct
85 Correct 3 ms 2804 KB Output is correct
86 Correct 4 ms 2804 KB Output is correct
87 Correct 5 ms 2900 KB Output is correct
88 Correct 4 ms 2900 KB Output is correct
89 Correct 4 ms 2804 KB Output is correct
90 Correct 5 ms 2900 KB Output is correct
91 Correct 4 ms 2900 KB Output is correct
92 Correct 3 ms 2900 KB Output is correct
93 Correct 4 ms 2848 KB Output is correct
94 Correct 2 ms 2644 KB Output is correct
95 Correct 6 ms 2668 KB Output is correct
96 Correct 3 ms 2664 KB Output is correct
97 Correct 2 ms 2644 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 2660 KB Output is correct
101 Correct 2 ms 2644 KB Output is correct
102 Correct 3 ms 2664 KB Output is correct
103 Correct 3 ms 2644 KB Output is correct
104 Correct 12 ms 4144 KB Output is correct
105 Correct 28 ms 7020 KB Output is correct
106 Correct 3 ms 2644 KB Output is correct
107 Correct 46 ms 10716 KB Output is correct
108 Correct 61 ms 16460 KB Output is correct
109 Correct 3 ms 2796 KB Output is correct
110 Correct 71 ms 16872 KB Output is correct
111 Correct 119 ms 19636 KB Output is correct
112 Correct 3 ms 2772 KB Output is correct
113 Correct 168 ms 35864 KB Output is correct
114 Correct 33 ms 6632 KB Output is correct
115 Correct 30 ms 6704 KB Output is correct
116 Correct 28 ms 6732 KB Output is correct
117 Correct 29 ms 6660 KB Output is correct
118 Correct 33 ms 6644 KB Output is correct
119 Correct 33 ms 7428 KB Output is correct
120 Correct 34 ms 6904 KB Output is correct
121 Correct 32 ms 6612 KB Output is correct
122 Correct 33 ms 6576 KB Output is correct
123 Correct 43 ms 6844 KB Output is correct
124 Correct 2 ms 2644 KB Output is correct
125 Correct 8 ms 4300 KB Output is correct
126 Correct 6 ms 4300 KB Output is correct
127 Correct 6 ms 4172 KB Output is correct
128 Correct 6 ms 4300 KB Output is correct
129 Correct 6 ms 4240 KB Output is correct
130 Correct 6 ms 3916 KB Output is correct
131 Correct 7 ms 4300 KB Output is correct
132 Correct 7 ms 4168 KB Output is correct
133 Incorrect 2 ms 2644 KB Output isn't correct
134 Halted 0 ms 0 KB -