Submission #367138

# Submission time Handle Problem Language Result Execution time Memory
367138 2021-02-16T10:50:19 Z idk321 Dreaming (IOI13_dreaming) C++11
47 / 100
279 ms 36716 KB
    #include "dreaming.h"

    #include <bits/stdc++.h>
    using namespace std;

    int n, m, l;
    const int N =100005;
    bool vis[N];
    multiset<int> ms[N];
    vector<array<int, 2>> adj[N];
    vector<array<int, 2>> comp;

    int dfs1(int node, int par)
    {
        vis[node] = true;
        int res = 0;
        ms[node].insert(0);
        for (auto next : adj[node])
        {
            if (next[0] == par) continue;
            int cur = dfs1(next[0], node) + next[1];
            res = max(res, cur);
            ms[node].insert(cur);
        }

        return res;
    }

    int dfs2(int node, int par, int pdist)
    {

        if (par != -1)
        {
            int del = *ms[node].rbegin() + pdist;
            ms[par].erase(ms[par].find(del));
            ms[node].insert(*ms[par].rbegin() + pdist);
            ms[par].insert(del);
        }
        int res = *ms[node].rbegin();


        for (auto next : adj[node])
        {

            if (next[0] == par) continue;

            res = min(res, dfs2(next[0], node, next[1]));
        }


        return res;
    }

    array<int, 2> dfs3(int node, int par)
    {
        array<int, 2> best = {node, 0};
        for (auto next : adj[node])
        {
            if (next[0] == par) continue;
            auto cur = dfs3(next[0],node);
            cur[1] += next[1];
            if (cur[1] > best[1])
            {
                best = cur;
            }
        }

        return best;
    }

    int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
        n = N;
        m = M;
        l = L;
        for (int i = 0; i < m; i++)
        {

            adj[A[i]].push_back({B[i], T[i]});
            adj[B[i]].push_back({A[i], T[i]});
        }

        int res = 0;
        vector<int> cents;
        for (int i = 0; i < n; i++)
        {
            if (!vis[i])
            {
                dfs1(i, -1);
                int cent = dfs2(i, -1, -1);
                auto cur = dfs3(i, -1);
                int mdist = dfs3(cur[0], -1)[1];
                res = max(res, mdist);
                cents.push_back(cent);
                comp.push_back({cent, mdist});
            }
        }

        sort(cents.rbegin(), cents.rend());

        if (m == n - 2)
        {
            res = max(res, cents[0] + cents[1] + l);
        } else
        {
            res = max(res, cents[0] + cents[1] + l);
            res = max(res, cents[1] + cents[2] + 2 * l);
        }

        return res;
    }
# Verdict Execution time Memory Grader output
1 Correct 150 ms 32876 KB Output is correct
2 Correct 159 ms 32748 KB Output is correct
3 Correct 99 ms 24044 KB Output is correct
4 Correct 21 ms 11116 KB Output is correct
5 Correct 16 ms 9708 KB Output is correct
6 Correct 29 ms 12908 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 64 ms 17004 KB Output is correct
9 Correct 115 ms 20864 KB Output is correct
10 Correct 7 ms 7532 KB Output is correct
11 Correct 142 ms 24812 KB Output is correct
12 Correct 166 ms 28780 KB Output is correct
13 Correct 6 ms 7660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 6 ms 7404 KB Output is correct
4 Correct 7 ms 7404 KB Output is correct
5 Correct 5 ms 7404 KB Output is correct
6 Correct 6 ms 7404 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 5 ms 7404 KB Output is correct
10 Correct 5 ms 7404 KB Output is correct
11 Correct 5 ms 7404 KB Output is correct
12 Correct 5 ms 7404 KB Output is correct
13 Correct 5 ms 7404 KB Output is correct
14 Correct 5 ms 7404 KB Output is correct
15 Correct 5 ms 7404 KB Output is correct
16 Correct 6 ms 7404 KB Output is correct
17 Correct 5 ms 7404 KB Output is correct
18 Correct 5 ms 7404 KB Output is correct
19 Correct 5 ms 7404 KB Output is correct
20 Correct 5 ms 7404 KB Output is correct
21 Correct 5 ms 7404 KB Output is correct
22 Correct 6 ms 7404 KB Output is correct
23 Correct 5 ms 7404 KB Output is correct
24 Correct 5 ms 7404 KB Output is correct
25 Correct 5 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 32876 KB Output is correct
2 Correct 159 ms 32748 KB Output is correct
3 Correct 99 ms 24044 KB Output is correct
4 Correct 21 ms 11116 KB Output is correct
5 Correct 16 ms 9708 KB Output is correct
6 Correct 29 ms 12908 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 64 ms 17004 KB Output is correct
9 Correct 115 ms 20864 KB Output is correct
10 Correct 7 ms 7532 KB Output is correct
11 Correct 142 ms 24812 KB Output is correct
12 Correct 166 ms 28780 KB Output is correct
13 Correct 6 ms 7660 KB Output is correct
14 Correct 5 ms 7404 KB Output is correct
15 Correct 5 ms 7404 KB Output is correct
16 Correct 6 ms 7404 KB Output is correct
17 Correct 7 ms 7404 KB Output is correct
18 Correct 5 ms 7404 KB Output is correct
19 Correct 6 ms 7404 KB Output is correct
20 Correct 5 ms 7404 KB Output is correct
21 Correct 5 ms 7404 KB Output is correct
22 Correct 5 ms 7404 KB Output is correct
23 Correct 5 ms 7404 KB Output is correct
24 Correct 5 ms 7404 KB Output is correct
25 Correct 5 ms 7404 KB Output is correct
26 Correct 5 ms 7404 KB Output is correct
27 Correct 5 ms 7404 KB Output is correct
28 Correct 5 ms 7404 KB Output is correct
29 Correct 6 ms 7404 KB Output is correct
30 Correct 5 ms 7404 KB Output is correct
31 Correct 5 ms 7404 KB Output is correct
32 Correct 5 ms 7404 KB Output is correct
33 Correct 5 ms 7404 KB Output is correct
34 Correct 5 ms 7404 KB Output is correct
35 Correct 6 ms 7404 KB Output is correct
36 Correct 5 ms 7404 KB Output is correct
37 Correct 5 ms 7404 KB Output is correct
38 Correct 5 ms 7404 KB Output is correct
39 Correct 156 ms 32964 KB Output is correct
40 Correct 155 ms 32748 KB Output is correct
41 Correct 94 ms 24044 KB Output is correct
42 Correct 19 ms 11116 KB Output is correct
43 Correct 6 ms 7404 KB Output is correct
44 Correct 5 ms 7404 KB Output is correct
45 Correct 5 ms 7404 KB Output is correct
46 Correct 5 ms 7404 KB Output is correct
47 Correct 5 ms 7404 KB Output is correct
48 Correct 5 ms 7404 KB Output is correct
49 Correct 5 ms 7404 KB Output is correct
50 Correct 6 ms 7436 KB Output is correct
51 Correct 7 ms 7404 KB Output is correct
52 Correct 5 ms 7404 KB Output is correct
53 Correct 5 ms 7404 KB Output is correct
54 Correct 5 ms 7404 KB Output is correct
55 Correct 5 ms 7404 KB Output is correct
56 Correct 5 ms 7424 KB Output is correct
57 Correct 198 ms 26732 KB Output is correct
58 Correct 190 ms 26732 KB Output is correct
59 Correct 205 ms 26732 KB Output is correct
60 Correct 199 ms 26860 KB Output is correct
61 Correct 189 ms 26604 KB Output is correct
62 Correct 200 ms 26552 KB Output is correct
63 Correct 186 ms 26348 KB Output is correct
64 Correct 183 ms 26348 KB Output is correct
65 Correct 187 ms 26348 KB Output is correct
66 Correct 181 ms 26476 KB Output is correct
67 Correct 202 ms 26860 KB Output is correct
68 Correct 210 ms 26732 KB Output is correct
69 Correct 218 ms 26732 KB Output is correct
70 Correct 203 ms 26732 KB Output is correct
71 Correct 5 ms 7404 KB Output is correct
72 Correct 8 ms 7916 KB Output is correct
73 Correct 8 ms 7916 KB Output is correct
74 Correct 8 ms 7916 KB Output is correct
75 Correct 8 ms 7916 KB Output is correct
76 Correct 8 ms 7916 KB Output is correct
77 Correct 8 ms 7916 KB Output is correct
78 Correct 9 ms 7916 KB Output is correct
79 Correct 8 ms 7916 KB Output is correct
80 Correct 279 ms 26604 KB Output is correct
81 Correct 191 ms 26604 KB Output is correct
82 Correct 188 ms 26604 KB Output is correct
83 Correct 234 ms 26604 KB Output is correct
84 Correct 9 ms 7788 KB Output is correct
85 Correct 7 ms 7788 KB Output is correct
86 Correct 7 ms 7828 KB Output is correct
87 Correct 8 ms 7916 KB Output is correct
88 Correct 9 ms 7916 KB Output is correct
89 Correct 9 ms 7916 KB Output is correct
90 Correct 8 ms 7916 KB Output is correct
91 Correct 10 ms 7916 KB Output is correct
92 Correct 8 ms 7916 KB Output is correct
93 Correct 8 ms 7916 KB Output is correct
94 Correct 6 ms 7404 KB Output is correct
95 Correct 5 ms 7404 KB Output is correct
96 Correct 5 ms 7404 KB Output is correct
97 Correct 5 ms 7404 KB Output is correct
98 Correct 5 ms 7404 KB Output is correct
99 Correct 5 ms 7404 KB Output is correct
100 Correct 5 ms 7404 KB Output is correct
101 Correct 5 ms 7404 KB Output is correct
102 Correct 5 ms 7404 KB Output is correct
103 Correct 5 ms 7404 KB Output is correct
104 Correct 16 ms 9708 KB Output is correct
105 Correct 32 ms 12908 KB Output is correct
106 Correct 5 ms 7404 KB Output is correct
107 Correct 66 ms 17004 KB Output is correct
108 Correct 88 ms 20844 KB Output is correct
109 Correct 7 ms 7532 KB Output is correct
110 Correct 150 ms 24812 KB Output is correct
111 Correct 166 ms 28652 KB Output is correct
112 Correct 6 ms 7660 KB Output is correct
113 Correct 234 ms 36716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 17804 KB Output is correct
2 Correct 65 ms 18276 KB Output is correct
3 Correct 64 ms 18272 KB Output is correct
4 Correct 52 ms 18272 KB Output is correct
5 Correct 52 ms 18272 KB Output is correct
6 Correct 56 ms 19424 KB Output is correct
7 Correct 57 ms 18784 KB Output is correct
8 Correct 51 ms 18016 KB Output is correct
9 Correct 61 ms 18020 KB Output is correct
10 Correct 67 ms 18660 KB Output is correct
11 Correct 9 ms 7404 KB Output is correct
12 Correct 26 ms 13400 KB Output is correct
13 Correct 22 ms 13436 KB Output is correct
14 Correct 24 ms 13400 KB Output is correct
15 Correct 24 ms 13400 KB Output is correct
16 Correct 26 ms 13400 KB Output is correct
17 Correct 19 ms 13400 KB Output is correct
18 Correct 22 ms 13528 KB Output is correct
19 Correct 20 ms 13400 KB Output is correct
20 Incorrect 5 ms 7404 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 6 ms 7404 KB Output is correct
4 Correct 7 ms 7404 KB Output is correct
5 Correct 5 ms 7404 KB Output is correct
6 Correct 6 ms 7404 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 5 ms 7404 KB Output is correct
9 Correct 5 ms 7404 KB Output is correct
10 Correct 5 ms 7404 KB Output is correct
11 Correct 5 ms 7404 KB Output is correct
12 Correct 5 ms 7404 KB Output is correct
13 Correct 5 ms 7404 KB Output is correct
14 Correct 5 ms 7404 KB Output is correct
15 Correct 5 ms 7404 KB Output is correct
16 Correct 6 ms 7404 KB Output is correct
17 Correct 5 ms 7404 KB Output is correct
18 Correct 5 ms 7404 KB Output is correct
19 Correct 5 ms 7404 KB Output is correct
20 Correct 5 ms 7404 KB Output is correct
21 Correct 5 ms 7404 KB Output is correct
22 Correct 6 ms 7404 KB Output is correct
23 Correct 5 ms 7404 KB Output is correct
24 Correct 5 ms 7404 KB Output is correct
25 Correct 5 ms 7404 KB Output is correct
26 Correct 6 ms 7532 KB Output is correct
27 Correct 8 ms 7788 KB Output is correct
28 Correct 10 ms 8064 KB Output is correct
29 Correct 6 ms 7532 KB Output is correct
30 Correct 7 ms 7756 KB Output is correct
31 Correct 8 ms 7916 KB Output is correct
32 Correct 6 ms 7532 KB Output is correct
33 Correct 8 ms 7788 KB Output is correct
34 Correct 8 ms 7916 KB Output is correct
35 Correct 5 ms 7404 KB Output is correct
36 Correct 6 ms 7404 KB Output is correct
37 Correct 5 ms 7404 KB Output is correct
38 Correct 6 ms 7432 KB Output is correct
39 Correct 5 ms 7404 KB Output is correct
40 Correct 6 ms 7404 KB Output is correct
41 Correct 5 ms 7404 KB Output is correct
42 Correct 7 ms 7404 KB Output is correct
43 Correct 5 ms 7404 KB Output is correct
44 Correct 6 ms 7404 KB Output is correct
45 Correct 5 ms 7404 KB Output is correct
46 Correct 6 ms 7404 KB Output is correct
47 Correct 7 ms 7404 KB Output is correct
48 Correct 7 ms 7404 KB Output is correct
49 Correct 5 ms 7404 KB Output is correct
50 Correct 5 ms 7404 KB Output is correct
51 Correct 5 ms 7404 KB Output is correct
52 Incorrect 5 ms 7404 KB Output isn't correct
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 150 ms 32876 KB Output is correct
2 Correct 159 ms 32748 KB Output is correct
3 Correct 99 ms 24044 KB Output is correct
4 Correct 21 ms 11116 KB Output is correct
5 Correct 16 ms 9708 KB Output is correct
6 Correct 29 ms 12908 KB Output is correct
7 Correct 5 ms 7404 KB Output is correct
8 Correct 64 ms 17004 KB Output is correct
9 Correct 115 ms 20864 KB Output is correct
10 Correct 7 ms 7532 KB Output is correct
11 Correct 142 ms 24812 KB Output is correct
12 Correct 166 ms 28780 KB Output is correct
13 Correct 6 ms 7660 KB Output is correct
14 Correct 5 ms 7404 KB Output is correct
15 Correct 5 ms 7404 KB Output is correct
16 Correct 6 ms 7404 KB Output is correct
17 Correct 7 ms 7404 KB Output is correct
18 Correct 5 ms 7404 KB Output is correct
19 Correct 6 ms 7404 KB Output is correct
20 Correct 5 ms 7404 KB Output is correct
21 Correct 5 ms 7404 KB Output is correct
22 Correct 5 ms 7404 KB Output is correct
23 Correct 5 ms 7404 KB Output is correct
24 Correct 5 ms 7404 KB Output is correct
25 Correct 5 ms 7404 KB Output is correct
26 Correct 5 ms 7404 KB Output is correct
27 Correct 5 ms 7404 KB Output is correct
28 Correct 5 ms 7404 KB Output is correct
29 Correct 6 ms 7404 KB Output is correct
30 Correct 5 ms 7404 KB Output is correct
31 Correct 5 ms 7404 KB Output is correct
32 Correct 5 ms 7404 KB Output is correct
33 Correct 5 ms 7404 KB Output is correct
34 Correct 5 ms 7404 KB Output is correct
35 Correct 6 ms 7404 KB Output is correct
36 Correct 5 ms 7404 KB Output is correct
37 Correct 5 ms 7404 KB Output is correct
38 Correct 5 ms 7404 KB Output is correct
39 Correct 156 ms 32964 KB Output is correct
40 Correct 155 ms 32748 KB Output is correct
41 Correct 94 ms 24044 KB Output is correct
42 Correct 19 ms 11116 KB Output is correct
43 Correct 6 ms 7404 KB Output is correct
44 Correct 5 ms 7404 KB Output is correct
45 Correct 5 ms 7404 KB Output is correct
46 Correct 5 ms 7404 KB Output is correct
47 Correct 5 ms 7404 KB Output is correct
48 Correct 5 ms 7404 KB Output is correct
49 Correct 5 ms 7404 KB Output is correct
50 Correct 6 ms 7436 KB Output is correct
51 Correct 7 ms 7404 KB Output is correct
52 Correct 5 ms 7404 KB Output is correct
53 Correct 5 ms 7404 KB Output is correct
54 Correct 5 ms 7404 KB Output is correct
55 Correct 5 ms 7404 KB Output is correct
56 Correct 5 ms 7424 KB Output is correct
57 Correct 198 ms 26732 KB Output is correct
58 Correct 190 ms 26732 KB Output is correct
59 Correct 205 ms 26732 KB Output is correct
60 Correct 199 ms 26860 KB Output is correct
61 Correct 189 ms 26604 KB Output is correct
62 Correct 200 ms 26552 KB Output is correct
63 Correct 186 ms 26348 KB Output is correct
64 Correct 183 ms 26348 KB Output is correct
65 Correct 187 ms 26348 KB Output is correct
66 Correct 181 ms 26476 KB Output is correct
67 Correct 202 ms 26860 KB Output is correct
68 Correct 210 ms 26732 KB Output is correct
69 Correct 218 ms 26732 KB Output is correct
70 Correct 203 ms 26732 KB Output is correct
71 Correct 5 ms 7404 KB Output is correct
72 Correct 8 ms 7916 KB Output is correct
73 Correct 8 ms 7916 KB Output is correct
74 Correct 8 ms 7916 KB Output is correct
75 Correct 8 ms 7916 KB Output is correct
76 Correct 8 ms 7916 KB Output is correct
77 Correct 8 ms 7916 KB Output is correct
78 Correct 9 ms 7916 KB Output is correct
79 Correct 8 ms 7916 KB Output is correct
80 Correct 279 ms 26604 KB Output is correct
81 Correct 191 ms 26604 KB Output is correct
82 Correct 188 ms 26604 KB Output is correct
83 Correct 234 ms 26604 KB Output is correct
84 Correct 9 ms 7788 KB Output is correct
85 Correct 7 ms 7788 KB Output is correct
86 Correct 7 ms 7828 KB Output is correct
87 Correct 8 ms 7916 KB Output is correct
88 Correct 9 ms 7916 KB Output is correct
89 Correct 9 ms 7916 KB Output is correct
90 Correct 8 ms 7916 KB Output is correct
91 Correct 10 ms 7916 KB Output is correct
92 Correct 8 ms 7916 KB Output is correct
93 Correct 8 ms 7916 KB Output is correct
94 Correct 6 ms 7404 KB Output is correct
95 Correct 5 ms 7404 KB Output is correct
96 Correct 5 ms 7404 KB Output is correct
97 Correct 5 ms 7404 KB Output is correct
98 Correct 5 ms 7404 KB Output is correct
99 Correct 5 ms 7404 KB Output is correct
100 Correct 5 ms 7404 KB Output is correct
101 Correct 5 ms 7404 KB Output is correct
102 Correct 5 ms 7404 KB Output is correct
103 Correct 5 ms 7404 KB Output is correct
104 Correct 16 ms 9708 KB Output is correct
105 Correct 32 ms 12908 KB Output is correct
106 Correct 5 ms 7404 KB Output is correct
107 Correct 66 ms 17004 KB Output is correct
108 Correct 88 ms 20844 KB Output is correct
109 Correct 7 ms 7532 KB Output is correct
110 Correct 150 ms 24812 KB Output is correct
111 Correct 166 ms 28652 KB Output is correct
112 Correct 6 ms 7660 KB Output is correct
113 Correct 234 ms 36716 KB Output is correct
114 Correct 51 ms 17804 KB Output is correct
115 Correct 65 ms 18276 KB Output is correct
116 Correct 64 ms 18272 KB Output is correct
117 Correct 52 ms 18272 KB Output is correct
118 Correct 52 ms 18272 KB Output is correct
119 Correct 56 ms 19424 KB Output is correct
120 Correct 57 ms 18784 KB Output is correct
121 Correct 51 ms 18016 KB Output is correct
122 Correct 61 ms 18020 KB Output is correct
123 Correct 67 ms 18660 KB Output is correct
124 Correct 9 ms 7404 KB Output is correct
125 Correct 26 ms 13400 KB Output is correct
126 Correct 22 ms 13436 KB Output is correct
127 Correct 24 ms 13400 KB Output is correct
128 Correct 24 ms 13400 KB Output is correct
129 Correct 26 ms 13400 KB Output is correct
130 Correct 19 ms 13400 KB Output is correct
131 Correct 22 ms 13528 KB Output is correct
132 Correct 20 ms 13400 KB Output is correct
133 Incorrect 5 ms 7404 KB Output isn't correct
134 Halted 0 ms 0 KB -