Submission #155847

# Submission time Handle Problem Language Result Execution time Memory
155847 2019-10-01T04:56:23 Z TAISA_ Dreaming (IOI13_dreaming) C++14
65 / 100
268 ms 34808 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1LL;
vector<vector<P>> G;
vector<int> dep, dp, vis;
vector<multiset<int>> st;
void build(int i, int p, int d) {
    vis[i] = 1;
    dep[i] = d;
    dp[i] = dep[i];
    for (auto &e : G[i]) {
        if (e.first == p) {
            continue;
        }
        build(e.first, i, d + e.second);
        dp[i] = max(dp[i], dp[e.first]);
        st[i].insert(dp[e.first] - dep[i]);
    }
}
pair<int, int> calc(int i, int p) {
    int res = INF, dia = 0;
    if (st[i].size() > 0) {
        auto itr = st[i].end();
        --itr;
        res = (*itr);
    }
    if (st[i].size() > 1) {
        auto itr = st[i].end();
        --itr;
        dia += (*itr);
        // cout << i << " " << (*itr) << endl;
        --itr;
        dia += (*itr);
        // cout << i << " " << (*itr) << endl;
    }
    for (auto &e : G[i]) {
        if (e.first == p) {
            continue;
        }
        int t = dp[e.first] - dep[i];
        st[i].erase(st[i].find(t));
        if (st[i].size() > 0) {
            auto it = st[i].end();
            --it;
            st[e.first].insert((*it) + e.second);
        } else {
            st[e.first].insert(e.second);
        }
        pair<int, int> re = calc(e.first, i);
        res = min(res, re.first);
        dia = max(dia, re.second);
        st[i].insert(t);
    }
    //  cout << i << " " << res << endl;
    return make_pair(res, dia);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    if (M == N - 1) {
        return 0;
    }
    G.resize(N);
    st.resize(N);
    dep.resize(N);
    dp.resize(N);
    vis.resize(N);
    for (int i = 0; i < M; i++) {
        G[A[i]].push_back(P(B[i], T[i]));
        G[B[i]].push_back(P(A[i], T[i]));
    }
    vector<ll> s;
    ll ma = 0;
    for (int i = 0; i < N; i++) {
        if (!vis[i]) {
            if (G[i].size() == 0) {
                s.push_back(0);
                continue;
            }
            build(i, -1, 0);
            pair<int, int> re = calc(i, -1);
            ma = max(ma, (ll)re.second);
            //   cout << re.second << endl;
            s.push_back(re.first);
        }
    }
    sort(all(s));
    reverse(all(s));
    ll ans = ma;
    if (s.size() > 1) {
        ans = max(ans, s[0] + s[1] + L);
    }
    if (s.size() > 2) {
        ans = max(ans, s[1] + s[2] + 2LL * L);
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 128 ms 25848 KB Output is correct
2 Correct 133 ms 26588 KB Output is correct
3 Correct 79 ms 20096 KB Output is correct
4 Correct 16 ms 4216 KB Output is correct
5 Correct 13 ms 2936 KB Output is correct
6 Correct 26 ms 6264 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 53 ms 11768 KB Output is correct
9 Correct 71 ms 16308 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 109 ms 20432 KB Output is correct
12 Correct 137 ms 23544 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 25848 KB Output is correct
2 Correct 133 ms 26588 KB Output is correct
3 Correct 79 ms 20096 KB Output is correct
4 Correct 16 ms 4216 KB Output is correct
5 Correct 13 ms 2936 KB Output is correct
6 Correct 26 ms 6264 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 53 ms 11768 KB Output is correct
9 Correct 71 ms 16308 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 109 ms 20432 KB Output is correct
12 Correct 137 ms 23544 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 380 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 276 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 25848 KB Output is correct
2 Correct 133 ms 26588 KB Output is correct
3 Correct 79 ms 20096 KB Output is correct
4 Correct 16 ms 4216 KB Output is correct
5 Correct 13 ms 2936 KB Output is correct
6 Correct 26 ms 6264 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 53 ms 11768 KB Output is correct
9 Correct 71 ms 16308 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 109 ms 20432 KB Output is correct
12 Correct 137 ms 23544 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 380 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 276 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 135 ms 27128 KB Output is correct
40 Correct 129 ms 26616 KB Output is correct
41 Correct 75 ms 20064 KB Output is correct
42 Correct 16 ms 4216 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 376 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 376 KB Output is correct
54 Correct 2 ms 376 KB Output is correct
55 Correct 2 ms 376 KB Output is correct
56 Correct 2 ms 376 KB Output is correct
57 Correct 181 ms 24504 KB Output is correct
58 Correct 162 ms 24440 KB Output is correct
59 Correct 170 ms 24436 KB Output is correct
60 Correct 164 ms 24368 KB Output is correct
61 Correct 172 ms 24544 KB Output is correct
62 Correct 268 ms 24528 KB Output is correct
63 Correct 165 ms 24180 KB Output is correct
64 Correct 170 ms 24140 KB Output is correct
65 Correct 178 ms 24376 KB Output is correct
66 Correct 164 ms 24420 KB Output is correct
67 Correct 163 ms 24408 KB Output is correct
68 Correct 166 ms 24440 KB Output is correct
69 Correct 159 ms 24952 KB Output is correct
70 Correct 174 ms 24728 KB Output is correct
71 Correct 2 ms 376 KB Output is correct
72 Correct 5 ms 1144 KB Output is correct
73 Correct 5 ms 1116 KB Output is correct
74 Correct 5 ms 1016 KB Output is correct
75 Correct 5 ms 1064 KB Output is correct
76 Correct 5 ms 1004 KB Output is correct
77 Correct 5 ms 1016 KB Output is correct
78 Correct 5 ms 1016 KB Output is correct
79 Correct 5 ms 1144 KB Output is correct
80 Correct 181 ms 24440 KB Output is correct
81 Correct 173 ms 24440 KB Output is correct
82 Correct 166 ms 24440 KB Output is correct
83 Correct 183 ms 24524 KB Output is correct
84 Correct 4 ms 1016 KB Output is correct
85 Correct 4 ms 888 KB Output is correct
86 Correct 5 ms 888 KB Output is correct
87 Correct 5 ms 888 KB Output is correct
88 Correct 5 ms 988 KB Output is correct
89 Correct 5 ms 888 KB Output is correct
90 Correct 5 ms 1016 KB Output is correct
91 Correct 5 ms 1016 KB Output is correct
92 Correct 5 ms 1016 KB Output is correct
93 Correct 5 ms 1016 KB Output is correct
94 Correct 2 ms 376 KB Output is correct
95 Correct 3 ms 376 KB Output is correct
96 Correct 2 ms 376 KB Output is correct
97 Correct 2 ms 376 KB Output is correct
98 Correct 2 ms 376 KB Output is correct
99 Correct 2 ms 376 KB Output is correct
100 Correct 2 ms 376 KB Output is correct
101 Correct 2 ms 376 KB Output is correct
102 Correct 3 ms 376 KB Output is correct
103 Correct 2 ms 376 KB Output is correct
104 Correct 13 ms 2936 KB Output is correct
105 Correct 26 ms 6264 KB Output is correct
106 Correct 2 ms 376 KB Output is correct
107 Correct 49 ms 11768 KB Output is correct
108 Correct 71 ms 16248 KB Output is correct
109 Correct 2 ms 504 KB Output is correct
110 Correct 112 ms 20476 KB Output is correct
111 Correct 137 ms 23584 KB Output is correct
112 Correct 3 ms 632 KB Output is correct
113 Correct 267 ms 34808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 13836 KB Output is correct
2 Correct 69 ms 13856 KB Output is correct
3 Correct 62 ms 13808 KB Output is correct
4 Correct 66 ms 13808 KB Output is correct
5 Correct 63 ms 13808 KB Output is correct
6 Correct 69 ms 15088 KB Output is correct
7 Correct 64 ms 14452 KB Output is correct
8 Correct 61 ms 13552 KB Output is correct
9 Correct 57 ms 13552 KB Output is correct
10 Correct 62 ms 14288 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 15 ms 9712 KB Output is correct
13 Correct 15 ms 9712 KB Output is correct
14 Correct 16 ms 9712 KB Output is correct
15 Correct 13 ms 9712 KB Output is correct
16 Correct 14 ms 9788 KB Output is correct
17 Correct 13 ms 9712 KB Output is correct
18 Correct 13 ms 9840 KB Output is correct
19 Correct 13 ms 9712 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 296 KB Output is correct
22 Correct 2 ms 632 KB Output is correct
23 Correct 13 ms 9712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 25848 KB Output is correct
2 Correct 133 ms 26588 KB Output is correct
3 Correct 79 ms 20096 KB Output is correct
4 Correct 16 ms 4216 KB Output is correct
5 Correct 13 ms 2936 KB Output is correct
6 Correct 26 ms 6264 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 53 ms 11768 KB Output is correct
9 Correct 71 ms 16308 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 109 ms 20432 KB Output is correct
12 Correct 137 ms 23544 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 4 ms 760 KB Output is correct
16 Correct 5 ms 1016 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 4 ms 760 KB Output is correct
19 Correct 5 ms 1016 KB Output is correct
20 Correct 3 ms 508 KB Output is correct
21 Correct 4 ms 760 KB Output is correct
22 Correct 5 ms 1016 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 256 KB Output is correct
41 Correct 2 ms 256 KB Output is correct
42 Incorrect 3 ms 376 KB Output isn't correct
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 128 ms 25848 KB Output is correct
2 Correct 133 ms 26588 KB Output is correct
3 Correct 79 ms 20096 KB Output is correct
4 Correct 16 ms 4216 KB Output is correct
5 Correct 13 ms 2936 KB Output is correct
6 Correct 26 ms 6264 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 53 ms 11768 KB Output is correct
9 Correct 71 ms 16308 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 109 ms 20432 KB Output is correct
12 Correct 137 ms 23544 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 380 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 276 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 135 ms 27128 KB Output is correct
40 Correct 129 ms 26616 KB Output is correct
41 Correct 75 ms 20064 KB Output is correct
42 Correct 16 ms 4216 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 376 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 376 KB Output is correct
54 Correct 2 ms 376 KB Output is correct
55 Correct 2 ms 376 KB Output is correct
56 Correct 2 ms 376 KB Output is correct
57 Correct 181 ms 24504 KB Output is correct
58 Correct 162 ms 24440 KB Output is correct
59 Correct 170 ms 24436 KB Output is correct
60 Correct 164 ms 24368 KB Output is correct
61 Correct 172 ms 24544 KB Output is correct
62 Correct 268 ms 24528 KB Output is correct
63 Correct 165 ms 24180 KB Output is correct
64 Correct 170 ms 24140 KB Output is correct
65 Correct 178 ms 24376 KB Output is correct
66 Correct 164 ms 24420 KB Output is correct
67 Correct 163 ms 24408 KB Output is correct
68 Correct 166 ms 24440 KB Output is correct
69 Correct 159 ms 24952 KB Output is correct
70 Correct 174 ms 24728 KB Output is correct
71 Correct 2 ms 376 KB Output is correct
72 Correct 5 ms 1144 KB Output is correct
73 Correct 5 ms 1116 KB Output is correct
74 Correct 5 ms 1016 KB Output is correct
75 Correct 5 ms 1064 KB Output is correct
76 Correct 5 ms 1004 KB Output is correct
77 Correct 5 ms 1016 KB Output is correct
78 Correct 5 ms 1016 KB Output is correct
79 Correct 5 ms 1144 KB Output is correct
80 Correct 181 ms 24440 KB Output is correct
81 Correct 173 ms 24440 KB Output is correct
82 Correct 166 ms 24440 KB Output is correct
83 Correct 183 ms 24524 KB Output is correct
84 Correct 4 ms 1016 KB Output is correct
85 Correct 4 ms 888 KB Output is correct
86 Correct 5 ms 888 KB Output is correct
87 Correct 5 ms 888 KB Output is correct
88 Correct 5 ms 988 KB Output is correct
89 Correct 5 ms 888 KB Output is correct
90 Correct 5 ms 1016 KB Output is correct
91 Correct 5 ms 1016 KB Output is correct
92 Correct 5 ms 1016 KB Output is correct
93 Correct 5 ms 1016 KB Output is correct
94 Correct 2 ms 376 KB Output is correct
95 Correct 3 ms 376 KB Output is correct
96 Correct 2 ms 376 KB Output is correct
97 Correct 2 ms 376 KB Output is correct
98 Correct 2 ms 376 KB Output is correct
99 Correct 2 ms 376 KB Output is correct
100 Correct 2 ms 376 KB Output is correct
101 Correct 2 ms 376 KB Output is correct
102 Correct 3 ms 376 KB Output is correct
103 Correct 2 ms 376 KB Output is correct
104 Correct 13 ms 2936 KB Output is correct
105 Correct 26 ms 6264 KB Output is correct
106 Correct 2 ms 376 KB Output is correct
107 Correct 49 ms 11768 KB Output is correct
108 Correct 71 ms 16248 KB Output is correct
109 Correct 2 ms 504 KB Output is correct
110 Correct 112 ms 20476 KB Output is correct
111 Correct 137 ms 23584 KB Output is correct
112 Correct 3 ms 632 KB Output is correct
113 Correct 267 ms 34808 KB Output is correct
114 Correct 62 ms 13836 KB Output is correct
115 Correct 69 ms 13856 KB Output is correct
116 Correct 62 ms 13808 KB Output is correct
117 Correct 66 ms 13808 KB Output is correct
118 Correct 63 ms 13808 KB Output is correct
119 Correct 69 ms 15088 KB Output is correct
120 Correct 64 ms 14452 KB Output is correct
121 Correct 61 ms 13552 KB Output is correct
122 Correct 57 ms 13552 KB Output is correct
123 Correct 62 ms 14288 KB Output is correct
124 Correct 2 ms 376 KB Output is correct
125 Correct 15 ms 9712 KB Output is correct
126 Correct 15 ms 9712 KB Output is correct
127 Correct 16 ms 9712 KB Output is correct
128 Correct 13 ms 9712 KB Output is correct
129 Correct 14 ms 9788 KB Output is correct
130 Correct 13 ms 9712 KB Output is correct
131 Correct 13 ms 9840 KB Output is correct
132 Correct 13 ms 9712 KB Output is correct
133 Correct 2 ms 256 KB Output is correct
134 Correct 2 ms 296 KB Output is correct
135 Correct 2 ms 632 KB Output is correct
136 Correct 13 ms 9712 KB Output is correct
137 Correct 3 ms 504 KB Output is correct
138 Correct 4 ms 760 KB Output is correct
139 Correct 5 ms 1016 KB Output is correct
140 Correct 3 ms 504 KB Output is correct
141 Correct 4 ms 760 KB Output is correct
142 Correct 5 ms 1016 KB Output is correct
143 Correct 3 ms 508 KB Output is correct
144 Correct 4 ms 760 KB Output is correct
145 Correct 5 ms 1016 KB Output is correct
146 Correct 2 ms 376 KB Output is correct
147 Correct 2 ms 376 KB Output is correct
148 Correct 2 ms 364 KB Output is correct
149 Correct 2 ms 376 KB Output is correct
150 Correct 2 ms 376 KB Output is correct
151 Correct 2 ms 376 KB Output is correct
152 Correct 2 ms 376 KB Output is correct
153 Correct 2 ms 376 KB Output is correct
154 Correct 2 ms 376 KB Output is correct
155 Correct 2 ms 376 KB Output is correct
156 Correct 2 ms 376 KB Output is correct
157 Correct 2 ms 376 KB Output is correct
158 Correct 2 ms 376 KB Output is correct
159 Correct 2 ms 376 KB Output is correct
160 Correct 2 ms 376 KB Output is correct
161 Correct 2 ms 376 KB Output is correct
162 Correct 2 ms 376 KB Output is correct
163 Correct 3 ms 256 KB Output is correct
164 Correct 2 ms 256 KB Output is correct
165 Incorrect 3 ms 376 KB Output isn't correct
166 Halted 0 ms 0 KB -