Submission #589216

# Submission time Handle Problem Language Result Execution time Memory
589216 2022-07-04T10:40:15 Z Vanilla Dreaming (IOI13_dreaming) C++17
47 / 100
115 ms 35820 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);
    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 91 ms 21324 KB Output is correct
2 Correct 71 ms 21528 KB Output is correct
3 Correct 45 ms 20408 KB Output is correct
4 Correct 9 ms 5460 KB Output is correct
5 Correct 9 ms 4084 KB Output is correct
6 Correct 15 ms 7028 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 30 ms 10676 KB Output is correct
9 Correct 46 ms 16468 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 66 ms 16852 KB Output is correct
12 Correct 91 ms 19668 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 2664 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 1 ms 2644 KB Output is correct
10 Correct 1 ms 2660 KB Output is correct
11 Correct 2 ms 2660 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2672 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 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 2664 KB Output is correct
22 Correct 1 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 2612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 21324 KB Output is correct
2 Correct 71 ms 21528 KB Output is correct
3 Correct 45 ms 20408 KB Output is correct
4 Correct 9 ms 5460 KB Output is correct
5 Correct 9 ms 4084 KB Output is correct
6 Correct 15 ms 7028 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 30 ms 10676 KB Output is correct
9 Correct 46 ms 16468 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 66 ms 16852 KB Output is correct
12 Correct 91 ms 19668 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 1 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 1 ms 2664 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 1 ms 2644 KB Output is correct
23 Correct 1 ms 2660 KB Output is correct
24 Correct 2 ms 2660 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2672 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 1 ms 2644 KB Output is correct
30 Correct 2 ms 2644 KB Output is correct
31 Correct 2 ms 2664 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 2664 KB Output is correct
35 Correct 1 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 2 ms 2612 KB Output is correct
39 Correct 65 ms 22476 KB Output is correct
40 Correct 72 ms 21532 KB Output is correct
41 Correct 46 ms 20360 KB Output is correct
42 Correct 9 ms 5488 KB Output is correct
43 Correct 3 ms 2660 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 2656 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 2 ms 2644 KB Output is correct
54 Correct 2 ms 2664 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 101 ms 11888 KB Output is correct
58 Correct 108 ms 11836 KB Output is correct
59 Correct 88 ms 11720 KB Output is correct
60 Correct 79 ms 11576 KB Output is correct
61 Correct 77 ms 11604 KB Output is correct
62 Correct 83 ms 11552 KB Output is correct
63 Correct 77 ms 11128 KB Output is correct
64 Correct 80 ms 11084 KB Output is correct
65 Correct 74 ms 11388 KB Output is correct
66 Correct 75 ms 11492 KB Output is correct
67 Correct 94 ms 11720 KB Output is correct
68 Correct 109 ms 11676 KB Output is correct
69 Correct 91 ms 11996 KB Output is correct
70 Correct 81 ms 11948 KB Output is correct
71 Correct 1 ms 2644 KB Output is correct
72 Correct 3 ms 2900 KB Output is correct
73 Correct 4 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 4 ms 2900 KB Output is correct
77 Correct 4 ms 2900 KB Output is correct
78 Correct 4 ms 2900 KB Output is correct
79 Correct 4 ms 2932 KB Output is correct
80 Correct 89 ms 11748 KB Output is correct
81 Correct 80 ms 11620 KB Output is correct
82 Correct 75 ms 11572 KB Output is correct
83 Correct 82 ms 11560 KB Output is correct
84 Correct 2 ms 2800 KB Output is correct
85 Correct 3 ms 2772 KB Output is correct
86 Correct 3 ms 2900 KB Output is correct
87 Correct 3 ms 2820 KB Output is correct
88 Correct 3 ms 2900 KB Output is correct
89 Correct 3 ms 2900 KB Output is correct
90 Correct 4 ms 2976 KB Output is correct
91 Correct 4 ms 2932 KB Output is correct
92 Correct 3 ms 2844 KB Output is correct
93 Correct 5 ms 2900 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 2644 KB Output is correct
98 Correct 2 ms 2644 KB Output is correct
99 Correct 2 ms 2620 KB Output is correct
100 Correct 2 ms 2644 KB Output is correct
101 Correct 2 ms 2664 KB Output is correct
102 Correct 1 ms 2644 KB Output is correct
103 Correct 2 ms 2664 KB Output is correct
104 Correct 7 ms 4084 KB Output is correct
105 Correct 17 ms 7008 KB Output is correct
106 Correct 2 ms 2644 KB Output is correct
107 Correct 33 ms 10736 KB Output is correct
108 Correct 50 ms 16500 KB Output is correct
109 Correct 2 ms 2772 KB Output is correct
110 Correct 76 ms 16824 KB Output is correct
111 Correct 77 ms 19660 KB Output is correct
112 Correct 2 ms 2772 KB Output is correct
113 Correct 115 ms 35820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 6248 KB Output is correct
2 Incorrect 24 ms 6352 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 2664 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 1 ms 2644 KB Output is correct
10 Correct 1 ms 2660 KB Output is correct
11 Correct 2 ms 2660 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2672 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 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 2664 KB Output is correct
22 Correct 1 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 2612 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2800 KB Output is correct
28 Correct 3 ms 2900 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 2 ms 2772 KB Output is correct
31 Correct 4 ms 2916 KB Output is correct
32 Incorrect 2 ms 2644 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 91 ms 21324 KB Output is correct
2 Correct 71 ms 21528 KB Output is correct
3 Correct 45 ms 20408 KB Output is correct
4 Correct 9 ms 5460 KB Output is correct
5 Correct 9 ms 4084 KB Output is correct
6 Correct 15 ms 7028 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 30 ms 10676 KB Output is correct
9 Correct 46 ms 16468 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 66 ms 16852 KB Output is correct
12 Correct 91 ms 19668 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 1 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 1 ms 2664 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 1 ms 2644 KB Output is correct
23 Correct 1 ms 2660 KB Output is correct
24 Correct 2 ms 2660 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2672 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 1 ms 2644 KB Output is correct
30 Correct 2 ms 2644 KB Output is correct
31 Correct 2 ms 2664 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 2664 KB Output is correct
35 Correct 1 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 2 ms 2612 KB Output is correct
39 Correct 65 ms 22476 KB Output is correct
40 Correct 72 ms 21532 KB Output is correct
41 Correct 46 ms 20360 KB Output is correct
42 Correct 9 ms 5488 KB Output is correct
43 Correct 3 ms 2660 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 2656 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 2 ms 2644 KB Output is correct
54 Correct 2 ms 2664 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 101 ms 11888 KB Output is correct
58 Correct 108 ms 11836 KB Output is correct
59 Correct 88 ms 11720 KB Output is correct
60 Correct 79 ms 11576 KB Output is correct
61 Correct 77 ms 11604 KB Output is correct
62 Correct 83 ms 11552 KB Output is correct
63 Correct 77 ms 11128 KB Output is correct
64 Correct 80 ms 11084 KB Output is correct
65 Correct 74 ms 11388 KB Output is correct
66 Correct 75 ms 11492 KB Output is correct
67 Correct 94 ms 11720 KB Output is correct
68 Correct 109 ms 11676 KB Output is correct
69 Correct 91 ms 11996 KB Output is correct
70 Correct 81 ms 11948 KB Output is correct
71 Correct 1 ms 2644 KB Output is correct
72 Correct 3 ms 2900 KB Output is correct
73 Correct 4 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 4 ms 2900 KB Output is correct
77 Correct 4 ms 2900 KB Output is correct
78 Correct 4 ms 2900 KB Output is correct
79 Correct 4 ms 2932 KB Output is correct
80 Correct 89 ms 11748 KB Output is correct
81 Correct 80 ms 11620 KB Output is correct
82 Correct 75 ms 11572 KB Output is correct
83 Correct 82 ms 11560 KB Output is correct
84 Correct 2 ms 2800 KB Output is correct
85 Correct 3 ms 2772 KB Output is correct
86 Correct 3 ms 2900 KB Output is correct
87 Correct 3 ms 2820 KB Output is correct
88 Correct 3 ms 2900 KB Output is correct
89 Correct 3 ms 2900 KB Output is correct
90 Correct 4 ms 2976 KB Output is correct
91 Correct 4 ms 2932 KB Output is correct
92 Correct 3 ms 2844 KB Output is correct
93 Correct 5 ms 2900 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 2644 KB Output is correct
98 Correct 2 ms 2644 KB Output is correct
99 Correct 2 ms 2620 KB Output is correct
100 Correct 2 ms 2644 KB Output is correct
101 Correct 2 ms 2664 KB Output is correct
102 Correct 1 ms 2644 KB Output is correct
103 Correct 2 ms 2664 KB Output is correct
104 Correct 7 ms 4084 KB Output is correct
105 Correct 17 ms 7008 KB Output is correct
106 Correct 2 ms 2644 KB Output is correct
107 Correct 33 ms 10736 KB Output is correct
108 Correct 50 ms 16500 KB Output is correct
109 Correct 2 ms 2772 KB Output is correct
110 Correct 76 ms 16824 KB Output is correct
111 Correct 77 ms 19660 KB Output is correct
112 Correct 2 ms 2772 KB Output is correct
113 Correct 115 ms 35820 KB Output is correct
114 Correct 21 ms 6248 KB Output is correct
115 Incorrect 24 ms 6352 KB Output isn't correct
116 Halted 0 ms 0 KB -