Submission #225847

# Submission time Handle Problem Language Result Execution time Memory
225847 2020-04-21T20:24:45 Z DS007 Dreaming (IOI13_dreaming) C++14
47 / 100
210 ms 26232 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;

const int MN = 1e5 + 5;
vector<pair<int, int>> adj[MN];
bool explored[MN];
vector<int> dia, dist;
multimap<int, int> m[MN];
int dp[MN];

int dfs(int v, int p = -1, int last = 0) {
    int val = max(last, dp[v]);
    for (auto i : adj[v]) {
        if (i.first == p)
            continue;

        auto itr = m[v].rbegin();
        if (itr->second == i.first && m[v].size() == 1)
            val = min(val, dfs(i.first, v, last + i.second));
        else if (itr->second == i.first)
            val = min(val, dfs(i.first, v, max(last, (++itr)->first) + i.second));
        else
            val = min(val, dfs(i.first, v, max(last, itr->first) + i.second));
    }

    dp[v] = max(dp[v], last);
    return val;
}

void pre(int v) {
    explored[v] = true;
    for (auto i : adj[v]) {
        if (!explored[i.first])
            pre(i.first), m[v].insert({dp[i.first] + i.second, i.first});
    }
    dp[v] = m[v].empty() ? 0 : m[v].rbegin()->first;
}

pair<int, int> longest(int v, int p = -1) {
    pair<int, int> ans = {0, v};
    for (auto i : adj[v]) {
        if (i.first == p)
            continue;

        auto temp = longest(i.first, v);
        ans = max(ans, {temp.first + i.second, temp.second});
    }
    return ans;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for (int i = 0; i < M; i++) {
        adj[A[i]].emplace_back(B[i], T[i]);
        adj[B[i]].emplace_back(A[i], T[i]);
    }

    for (int i = 0; i < N; i++) {
        if (!explored[i]) {
            pre(i), dist.push_back(dfs(i));
            auto temp = longest(i);
            dia.push_back(longest(temp.second).first);
        }
    }

    sort(dist.begin(), dist.end(), greater<>());
    int ans = *max_element(dia.begin(), dia.end());
    if (dist.size() > 1)
        ans = max(ans, dist[0] + dist[1] + L);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 100 ms 21752 KB Output is correct
2 Correct 94 ms 21752 KB Output is correct
3 Correct 61 ms 17912 KB Output is correct
4 Correct 18 ms 9472 KB Output is correct
5 Correct 16 ms 8704 KB Output is correct
6 Correct 31 ms 10624 KB Output is correct
7 Correct 8 ms 7424 KB Output is correct
8 Correct 46 ms 13048 KB Output is correct
9 Correct 69 ms 15864 KB Output is correct
10 Correct 9 ms 7552 KB Output is correct
11 Correct 114 ms 17144 KB Output is correct
12 Correct 147 ms 19540 KB Output is correct
13 Correct 11 ms 7552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 21752 KB Output is correct
2 Correct 94 ms 21752 KB Output is correct
3 Correct 61 ms 17912 KB Output is correct
4 Correct 18 ms 9472 KB Output is correct
5 Correct 16 ms 8704 KB Output is correct
6 Correct 31 ms 10624 KB Output is correct
7 Correct 8 ms 7424 KB Output is correct
8 Correct 46 ms 13048 KB Output is correct
9 Correct 69 ms 15864 KB Output is correct
10 Correct 9 ms 7552 KB Output is correct
11 Correct 114 ms 17144 KB Output is correct
12 Correct 147 ms 19540 KB Output is correct
13 Correct 11 ms 7552 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 9 ms 7424 KB Output is correct
16 Correct 10 ms 7424 KB Output is correct
17 Correct 9 ms 7424 KB Output is correct
18 Correct 9 ms 7424 KB Output is correct
19 Correct 9 ms 7424 KB Output is correct
20 Correct 9 ms 7424 KB Output is correct
21 Correct 9 ms 7424 KB Output is correct
22 Correct 10 ms 7424 KB Output is correct
23 Correct 9 ms 7424 KB Output is correct
24 Correct 8 ms 7424 KB Output is correct
25 Correct 10 ms 7424 KB Output is correct
26 Correct 9 ms 7424 KB Output is correct
27 Correct 10 ms 7424 KB Output is correct
28 Correct 8 ms 7424 KB Output is correct
29 Correct 8 ms 7424 KB Output is correct
30 Correct 8 ms 7424 KB Output is correct
31 Correct 9 ms 7424 KB Output is correct
32 Correct 9 ms 7424 KB Output is correct
33 Correct 8 ms 7424 KB Output is correct
34 Correct 8 ms 7424 KB Output is correct
35 Correct 8 ms 7424 KB Output is correct
36 Correct 10 ms 7424 KB Output is correct
37 Correct 8 ms 7424 KB Output is correct
38 Correct 8 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 21752 KB Output is correct
2 Correct 94 ms 21752 KB Output is correct
3 Correct 61 ms 17912 KB Output is correct
4 Correct 18 ms 9472 KB Output is correct
5 Correct 16 ms 8704 KB Output is correct
6 Correct 31 ms 10624 KB Output is correct
7 Correct 8 ms 7424 KB Output is correct
8 Correct 46 ms 13048 KB Output is correct
9 Correct 69 ms 15864 KB Output is correct
10 Correct 9 ms 7552 KB Output is correct
11 Correct 114 ms 17144 KB Output is correct
12 Correct 147 ms 19540 KB Output is correct
13 Correct 11 ms 7552 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 9 ms 7424 KB Output is correct
16 Correct 10 ms 7424 KB Output is correct
17 Correct 9 ms 7424 KB Output is correct
18 Correct 9 ms 7424 KB Output is correct
19 Correct 9 ms 7424 KB Output is correct
20 Correct 9 ms 7424 KB Output is correct
21 Correct 9 ms 7424 KB Output is correct
22 Correct 10 ms 7424 KB Output is correct
23 Correct 9 ms 7424 KB Output is correct
24 Correct 8 ms 7424 KB Output is correct
25 Correct 10 ms 7424 KB Output is correct
26 Correct 9 ms 7424 KB Output is correct
27 Correct 10 ms 7424 KB Output is correct
28 Correct 8 ms 7424 KB Output is correct
29 Correct 8 ms 7424 KB Output is correct
30 Correct 8 ms 7424 KB Output is correct
31 Correct 9 ms 7424 KB Output is correct
32 Correct 9 ms 7424 KB Output is correct
33 Correct 8 ms 7424 KB Output is correct
34 Correct 8 ms 7424 KB Output is correct
35 Correct 8 ms 7424 KB Output is correct
36 Correct 10 ms 7424 KB Output is correct
37 Correct 8 ms 7424 KB Output is correct
38 Correct 8 ms 7424 KB Output is correct
39 Correct 89 ms 21752 KB Output is correct
40 Correct 118 ms 21728 KB Output is correct
41 Correct 78 ms 17912 KB Output is correct
42 Correct 19 ms 9472 KB Output is correct
43 Correct 8 ms 7424 KB Output is correct
44 Correct 8 ms 7424 KB Output is correct
45 Correct 10 ms 7424 KB Output is correct
46 Correct 9 ms 7424 KB Output is correct
47 Correct 9 ms 7424 KB Output is correct
48 Correct 12 ms 7424 KB Output is correct
49 Correct 8 ms 7424 KB Output is correct
50 Correct 8 ms 7424 KB Output is correct
51 Correct 9 ms 7424 KB Output is correct
52 Correct 9 ms 7424 KB Output is correct
53 Correct 8 ms 7424 KB Output is correct
54 Correct 9 ms 7424 KB Output is correct
55 Correct 8 ms 7424 KB Output is correct
56 Correct 8 ms 7424 KB Output is correct
57 Correct 176 ms 17784 KB Output is correct
58 Correct 128 ms 17784 KB Output is correct
59 Correct 125 ms 17656 KB Output is correct
60 Correct 134 ms 17656 KB Output is correct
61 Correct 137 ms 17656 KB Output is correct
62 Correct 139 ms 17528 KB Output is correct
63 Correct 118 ms 17400 KB Output is correct
64 Correct 112 ms 17400 KB Output is correct
65 Correct 165 ms 17504 KB Output is correct
66 Correct 118 ms 17400 KB Output is correct
67 Correct 185 ms 17656 KB Output is correct
68 Correct 131 ms 17764 KB Output is correct
69 Correct 169 ms 17912 KB Output is correct
70 Correct 130 ms 17656 KB Output is correct
71 Correct 8 ms 7424 KB Output is correct
72 Correct 12 ms 7680 KB Output is correct
73 Correct 10 ms 7680 KB Output is correct
74 Correct 11 ms 7680 KB Output is correct
75 Correct 11 ms 7680 KB Output is correct
76 Correct 10 ms 7680 KB Output is correct
77 Correct 12 ms 7680 KB Output is correct
78 Correct 10 ms 7680 KB Output is correct
79 Correct 10 ms 7680 KB Output is correct
80 Correct 124 ms 17616 KB Output is correct
81 Correct 128 ms 17656 KB Output is correct
82 Correct 190 ms 17528 KB Output is correct
83 Correct 123 ms 17528 KB Output is correct
84 Correct 11 ms 7680 KB Output is correct
85 Correct 10 ms 7552 KB Output is correct
86 Correct 11 ms 7680 KB Output is correct
87 Correct 11 ms 7680 KB Output is correct
88 Correct 12 ms 7680 KB Output is correct
89 Correct 11 ms 7680 KB Output is correct
90 Correct 10 ms 7680 KB Output is correct
91 Correct 10 ms 7680 KB Output is correct
92 Correct 10 ms 7680 KB Output is correct
93 Correct 11 ms 7680 KB Output is correct
94 Correct 8 ms 7424 KB Output is correct
95 Correct 8 ms 7424 KB Output is correct
96 Correct 8 ms 7424 KB Output is correct
97 Correct 8 ms 7424 KB Output is correct
98 Correct 9 ms 7424 KB Output is correct
99 Correct 8 ms 7424 KB Output is correct
100 Correct 8 ms 7424 KB Output is correct
101 Correct 8 ms 7424 KB Output is correct
102 Correct 8 ms 7424 KB Output is correct
103 Correct 8 ms 7424 KB Output is correct
104 Correct 18 ms 8704 KB Output is correct
105 Correct 25 ms 10496 KB Output is correct
106 Correct 8 ms 7424 KB Output is correct
107 Correct 45 ms 13048 KB Output is correct
108 Correct 56 ms 15864 KB Output is correct
109 Correct 9 ms 7552 KB Output is correct
110 Correct 85 ms 17144 KB Output is correct
111 Correct 102 ms 19320 KB Output is correct
112 Correct 9 ms 7552 KB Output is correct
113 Correct 210 ms 26232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 12144 KB Output is correct
2 Incorrect 39 ms 12528 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 100 ms 21752 KB Output is correct
2 Correct 94 ms 21752 KB Output is correct
3 Correct 61 ms 17912 KB Output is correct
4 Correct 18 ms 9472 KB Output is correct
5 Correct 16 ms 8704 KB Output is correct
6 Correct 31 ms 10624 KB Output is correct
7 Correct 8 ms 7424 KB Output is correct
8 Correct 46 ms 13048 KB Output is correct
9 Correct 69 ms 15864 KB Output is correct
10 Correct 9 ms 7552 KB Output is correct
11 Correct 114 ms 17144 KB Output is correct
12 Correct 147 ms 19540 KB Output is correct
13 Correct 11 ms 7552 KB Output is correct
14 Correct 9 ms 7424 KB Output is correct
15 Correct 9 ms 7552 KB Output is correct
16 Correct 11 ms 7808 KB Output is correct
17 Correct 10 ms 7552 KB Output is correct
18 Correct 10 ms 7552 KB Output is correct
19 Correct 11 ms 7680 KB Output is correct
20 Incorrect 10 ms 7424 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 100 ms 21752 KB Output is correct
2 Correct 94 ms 21752 KB Output is correct
3 Correct 61 ms 17912 KB Output is correct
4 Correct 18 ms 9472 KB Output is correct
5 Correct 16 ms 8704 KB Output is correct
6 Correct 31 ms 10624 KB Output is correct
7 Correct 8 ms 7424 KB Output is correct
8 Correct 46 ms 13048 KB Output is correct
9 Correct 69 ms 15864 KB Output is correct
10 Correct 9 ms 7552 KB Output is correct
11 Correct 114 ms 17144 KB Output is correct
12 Correct 147 ms 19540 KB Output is correct
13 Correct 11 ms 7552 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 9 ms 7424 KB Output is correct
16 Correct 10 ms 7424 KB Output is correct
17 Correct 9 ms 7424 KB Output is correct
18 Correct 9 ms 7424 KB Output is correct
19 Correct 9 ms 7424 KB Output is correct
20 Correct 9 ms 7424 KB Output is correct
21 Correct 9 ms 7424 KB Output is correct
22 Correct 10 ms 7424 KB Output is correct
23 Correct 9 ms 7424 KB Output is correct
24 Correct 8 ms 7424 KB Output is correct
25 Correct 10 ms 7424 KB Output is correct
26 Correct 9 ms 7424 KB Output is correct
27 Correct 10 ms 7424 KB Output is correct
28 Correct 8 ms 7424 KB Output is correct
29 Correct 8 ms 7424 KB Output is correct
30 Correct 8 ms 7424 KB Output is correct
31 Correct 9 ms 7424 KB Output is correct
32 Correct 9 ms 7424 KB Output is correct
33 Correct 8 ms 7424 KB Output is correct
34 Correct 8 ms 7424 KB Output is correct
35 Correct 8 ms 7424 KB Output is correct
36 Correct 10 ms 7424 KB Output is correct
37 Correct 8 ms 7424 KB Output is correct
38 Correct 8 ms 7424 KB Output is correct
39 Correct 89 ms 21752 KB Output is correct
40 Correct 118 ms 21728 KB Output is correct
41 Correct 78 ms 17912 KB Output is correct
42 Correct 19 ms 9472 KB Output is correct
43 Correct 8 ms 7424 KB Output is correct
44 Correct 8 ms 7424 KB Output is correct
45 Correct 10 ms 7424 KB Output is correct
46 Correct 9 ms 7424 KB Output is correct
47 Correct 9 ms 7424 KB Output is correct
48 Correct 12 ms 7424 KB Output is correct
49 Correct 8 ms 7424 KB Output is correct
50 Correct 8 ms 7424 KB Output is correct
51 Correct 9 ms 7424 KB Output is correct
52 Correct 9 ms 7424 KB Output is correct
53 Correct 8 ms 7424 KB Output is correct
54 Correct 9 ms 7424 KB Output is correct
55 Correct 8 ms 7424 KB Output is correct
56 Correct 8 ms 7424 KB Output is correct
57 Correct 176 ms 17784 KB Output is correct
58 Correct 128 ms 17784 KB Output is correct
59 Correct 125 ms 17656 KB Output is correct
60 Correct 134 ms 17656 KB Output is correct
61 Correct 137 ms 17656 KB Output is correct
62 Correct 139 ms 17528 KB Output is correct
63 Correct 118 ms 17400 KB Output is correct
64 Correct 112 ms 17400 KB Output is correct
65 Correct 165 ms 17504 KB Output is correct
66 Correct 118 ms 17400 KB Output is correct
67 Correct 185 ms 17656 KB Output is correct
68 Correct 131 ms 17764 KB Output is correct
69 Correct 169 ms 17912 KB Output is correct
70 Correct 130 ms 17656 KB Output is correct
71 Correct 8 ms 7424 KB Output is correct
72 Correct 12 ms 7680 KB Output is correct
73 Correct 10 ms 7680 KB Output is correct
74 Correct 11 ms 7680 KB Output is correct
75 Correct 11 ms 7680 KB Output is correct
76 Correct 10 ms 7680 KB Output is correct
77 Correct 12 ms 7680 KB Output is correct
78 Correct 10 ms 7680 KB Output is correct
79 Correct 10 ms 7680 KB Output is correct
80 Correct 124 ms 17616 KB Output is correct
81 Correct 128 ms 17656 KB Output is correct
82 Correct 190 ms 17528 KB Output is correct
83 Correct 123 ms 17528 KB Output is correct
84 Correct 11 ms 7680 KB Output is correct
85 Correct 10 ms 7552 KB Output is correct
86 Correct 11 ms 7680 KB Output is correct
87 Correct 11 ms 7680 KB Output is correct
88 Correct 12 ms 7680 KB Output is correct
89 Correct 11 ms 7680 KB Output is correct
90 Correct 10 ms 7680 KB Output is correct
91 Correct 10 ms 7680 KB Output is correct
92 Correct 10 ms 7680 KB Output is correct
93 Correct 11 ms 7680 KB Output is correct
94 Correct 8 ms 7424 KB Output is correct
95 Correct 8 ms 7424 KB Output is correct
96 Correct 8 ms 7424 KB Output is correct
97 Correct 8 ms 7424 KB Output is correct
98 Correct 9 ms 7424 KB Output is correct
99 Correct 8 ms 7424 KB Output is correct
100 Correct 8 ms 7424 KB Output is correct
101 Correct 8 ms 7424 KB Output is correct
102 Correct 8 ms 7424 KB Output is correct
103 Correct 8 ms 7424 KB Output is correct
104 Correct 18 ms 8704 KB Output is correct
105 Correct 25 ms 10496 KB Output is correct
106 Correct 8 ms 7424 KB Output is correct
107 Correct 45 ms 13048 KB Output is correct
108 Correct 56 ms 15864 KB Output is correct
109 Correct 9 ms 7552 KB Output is correct
110 Correct 85 ms 17144 KB Output is correct
111 Correct 102 ms 19320 KB Output is correct
112 Correct 9 ms 7552 KB Output is correct
113 Correct 210 ms 26232 KB Output is correct
114 Correct 36 ms 12144 KB Output is correct
115 Incorrect 39 ms 12528 KB Output isn't correct
116 Halted 0 ms 0 KB -