Submission #589236

# Submission time Handle Problem Language Result Execution time Memory
589236 2022-07-04T10:51:06 Z Vanilla Dreaming (IOI13_dreaming) C++17
47 / 100
149 ms 34240 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 = 1e15;

                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]));
                    int idx = 0;
                    for (auto &[v, cost]: ad[u]) {
                        if (v == p) continue;
                        int64 p1 = (idx == 0 ? -1e15 : pref[idx-1]);
                        int64 p2 = (idx == suff.size() - 1 ? -1e15: 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] + (int64) L);
    else rs = max({rs, a[0] + a[1] + (int64) L, a[1] + a[2] + 2 * (int64) 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:64: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:60:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |                         int64 p2 = (idx == suff.size() - 1 ? -1e15: suff[idx + 1]);
      |                                     ~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 89 ms 21256 KB Output is correct
2 Correct 67 ms 20380 KB Output is correct
3 Correct 44 ms 19452 KB Output is correct
4 Correct 9 ms 5240 KB Output is correct
5 Correct 8 ms 3924 KB Output is correct
6 Correct 20 ms 6780 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 32 ms 10212 KB Output is correct
9 Correct 50 ms 15728 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 76 ms 15692 KB Output is correct
12 Correct 90 ms 18580 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 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 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 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 1 ms 2644 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 2 ms 2580 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 1 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 21256 KB Output is correct
2 Correct 67 ms 20380 KB Output is correct
3 Correct 44 ms 19452 KB Output is correct
4 Correct 9 ms 5240 KB Output is correct
5 Correct 8 ms 3924 KB Output is correct
6 Correct 20 ms 6780 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 32 ms 10212 KB Output is correct
9 Correct 50 ms 15728 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 76 ms 15692 KB Output is correct
12 Correct 90 ms 18580 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 2 ms 2648 KB Output is correct
15 Correct 2 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 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 1 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 1 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 1 ms 2644 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 1 ms 2644 KB Output is correct
31 Correct 2 ms 2580 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 1 ms 2644 KB Output is correct
37 Correct 1 ms 2644 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 66 ms 21356 KB Output is correct
40 Correct 66 ms 20404 KB Output is correct
41 Correct 49 ms 19392 KB Output is correct
42 Correct 9 ms 5332 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 2 ms 2560 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 2644 KB Output is correct
51 Correct 2 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 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 81 ms 10504 KB Output is correct
58 Correct 99 ms 10420 KB Output is correct
59 Correct 103 ms 10372 KB Output is correct
60 Correct 98 ms 10320 KB Output is correct
61 Correct 84 ms 10060 KB Output is correct
62 Correct 104 ms 10112 KB Output is correct
63 Correct 86 ms 9760 KB Output is correct
64 Correct 83 ms 9680 KB Output is correct
65 Correct 87 ms 9724 KB Output is correct
66 Correct 87 ms 9692 KB Output is correct
67 Correct 104 ms 10380 KB Output is correct
68 Correct 79 ms 10328 KB Output is correct
69 Correct 90 ms 10404 KB Output is correct
70 Correct 97 ms 10272 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 5 ms 2800 KB Output is correct
75 Correct 4 ms 2904 KB Output is correct
76 Correct 4 ms 2900 KB Output is correct
77 Correct 3 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 87 ms 10244 KB Output is correct
81 Correct 84 ms 10276 KB Output is correct
82 Correct 76 ms 10056 KB Output is correct
83 Correct 82 ms 10052 KB Output is correct
84 Correct 2 ms 2772 KB Output is correct
85 Correct 3 ms 2772 KB Output is correct
86 Correct 3 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 3 ms 2772 KB Output is correct
90 Correct 3 ms 2772 KB Output is correct
91 Correct 3 ms 2900 KB Output is correct
92 Correct 3 ms 2796 KB Output is correct
93 Correct 3 ms 2772 KB Output is correct
94 Correct 1 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 1 ms 2644 KB Output is correct
98 Correct 1 ms 2644 KB Output is correct
99 Correct 1 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 7 ms 3924 KB Output is correct
105 Correct 15 ms 6784 KB Output is correct
106 Correct 2 ms 2728 KB Output is correct
107 Correct 40 ms 10188 KB Output is correct
108 Correct 51 ms 15772 KB Output is correct
109 Correct 3 ms 2848 KB Output is correct
110 Correct 67 ms 15692 KB Output is correct
111 Correct 87 ms 18532 KB Output is correct
112 Correct 2 ms 2772 KB Output is correct
113 Correct 149 ms 34240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 6288 KB Output is correct
2 Correct 36 ms 6268 KB Output is correct
3 Correct 24 ms 6768 KB Output is correct
4 Correct 22 ms 6736 KB Output is correct
5 Correct 37 ms 6704 KB Output is correct
6 Correct 23 ms 7420 KB Output is correct
7 Correct 27 ms 6880 KB Output is correct
8 Correct 24 ms 6604 KB Output is correct
9 Correct 22 ms 6656 KB Output is correct
10 Correct 31 ms 6876 KB Output is correct
11 Correct 3 ms 2644 KB Output is correct
12 Correct 6 ms 4172 KB Output is correct
13 Correct 13 ms 4300 KB Output is correct
14 Correct 7 ms 4172 KB Output is correct
15 Correct 6 ms 4300 KB Output is correct
16 Correct 11 ms 4220 KB Output is correct
17 Correct 6 ms 3936 KB Output is correct
18 Correct 7 ms 4328 KB Output is correct
19 Correct 6 ms 4172 KB Output is correct
20 Incorrect 2 ms 2660 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2648 KB Output is correct
2 Correct 2 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 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 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 1 ms 2644 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 2 ms 2580 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 1 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 2 ms 2644 KB Output is correct
27 Correct 2 ms 2772 KB Output is correct
28 Correct 3 ms 2772 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 2 ms 2772 KB Output is correct
31 Correct 5 ms 2772 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 3 ms 2772 KB Output is correct
34 Correct 5 ms 2772 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 2644 KB Output is correct
38 Correct 1 ms 2644 KB Output is correct
39 Correct 2 ms 2644 KB Output is correct
40 Correct 2 ms 2644 KB Output is correct
41 Correct 2 ms 2644 KB Output is correct
42 Correct 1 ms 2644 KB Output is correct
43 Correct 1 ms 2644 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 3 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 1 ms 2644 KB Output is correct
50 Correct 2 ms 2644 KB Output is correct
51 Correct 2 ms 2644 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 89 ms 21256 KB Output is correct
2 Correct 67 ms 20380 KB Output is correct
3 Correct 44 ms 19452 KB Output is correct
4 Correct 9 ms 5240 KB Output is correct
5 Correct 8 ms 3924 KB Output is correct
6 Correct 20 ms 6780 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 32 ms 10212 KB Output is correct
9 Correct 50 ms 15728 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 76 ms 15692 KB Output is correct
12 Correct 90 ms 18580 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 2 ms 2648 KB Output is correct
15 Correct 2 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 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 1 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 1 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 1 ms 2644 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 1 ms 2644 KB Output is correct
31 Correct 2 ms 2580 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 1 ms 2644 KB Output is correct
37 Correct 1 ms 2644 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 66 ms 21356 KB Output is correct
40 Correct 66 ms 20404 KB Output is correct
41 Correct 49 ms 19392 KB Output is correct
42 Correct 9 ms 5332 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 2 ms 2560 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 2644 KB Output is correct
51 Correct 2 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 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 81 ms 10504 KB Output is correct
58 Correct 99 ms 10420 KB Output is correct
59 Correct 103 ms 10372 KB Output is correct
60 Correct 98 ms 10320 KB Output is correct
61 Correct 84 ms 10060 KB Output is correct
62 Correct 104 ms 10112 KB Output is correct
63 Correct 86 ms 9760 KB Output is correct
64 Correct 83 ms 9680 KB Output is correct
65 Correct 87 ms 9724 KB Output is correct
66 Correct 87 ms 9692 KB Output is correct
67 Correct 104 ms 10380 KB Output is correct
68 Correct 79 ms 10328 KB Output is correct
69 Correct 90 ms 10404 KB Output is correct
70 Correct 97 ms 10272 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 5 ms 2800 KB Output is correct
75 Correct 4 ms 2904 KB Output is correct
76 Correct 4 ms 2900 KB Output is correct
77 Correct 3 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 87 ms 10244 KB Output is correct
81 Correct 84 ms 10276 KB Output is correct
82 Correct 76 ms 10056 KB Output is correct
83 Correct 82 ms 10052 KB Output is correct
84 Correct 2 ms 2772 KB Output is correct
85 Correct 3 ms 2772 KB Output is correct
86 Correct 3 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 3 ms 2772 KB Output is correct
90 Correct 3 ms 2772 KB Output is correct
91 Correct 3 ms 2900 KB Output is correct
92 Correct 3 ms 2796 KB Output is correct
93 Correct 3 ms 2772 KB Output is correct
94 Correct 1 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 1 ms 2644 KB Output is correct
98 Correct 1 ms 2644 KB Output is correct
99 Correct 1 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 7 ms 3924 KB Output is correct
105 Correct 15 ms 6784 KB Output is correct
106 Correct 2 ms 2728 KB Output is correct
107 Correct 40 ms 10188 KB Output is correct
108 Correct 51 ms 15772 KB Output is correct
109 Correct 3 ms 2848 KB Output is correct
110 Correct 67 ms 15692 KB Output is correct
111 Correct 87 ms 18532 KB Output is correct
112 Correct 2 ms 2772 KB Output is correct
113 Correct 149 ms 34240 KB Output is correct
114 Correct 24 ms 6288 KB Output is correct
115 Correct 36 ms 6268 KB Output is correct
116 Correct 24 ms 6768 KB Output is correct
117 Correct 22 ms 6736 KB Output is correct
118 Correct 37 ms 6704 KB Output is correct
119 Correct 23 ms 7420 KB Output is correct
120 Correct 27 ms 6880 KB Output is correct
121 Correct 24 ms 6604 KB Output is correct
122 Correct 22 ms 6656 KB Output is correct
123 Correct 31 ms 6876 KB Output is correct
124 Correct 3 ms 2644 KB Output is correct
125 Correct 6 ms 4172 KB Output is correct
126 Correct 13 ms 4300 KB Output is correct
127 Correct 7 ms 4172 KB Output is correct
128 Correct 6 ms 4300 KB Output is correct
129 Correct 11 ms 4220 KB Output is correct
130 Correct 6 ms 3936 KB Output is correct
131 Correct 7 ms 4328 KB Output is correct
132 Correct 6 ms 4172 KB Output is correct
133 Incorrect 2 ms 2660 KB Output isn't correct
134 Halted 0 ms 0 KB -