Submission #156339

# Submission time Handle Problem Language Result Execution time Memory
156339 2019-10-05T08:49:46 Z Alexa2001 Dreaming (IOI13_dreaming) C++17
42 / 100
119 ms 15348 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 1e5 + 5;

vector<int> dia, mn, nodes;
vector<pair<int,int>> v[Nmax];
int dist[3][Nmax];
bool used[Nmax];

void dfs(int node, int t, int dad = 0)
{
    if(!t) nodes.push_back(node), used[node] = 1;

    for(auto it : v[node])
        if(it.first != dad)
        {
            dist[t][it.first] = dist[t][node] + it.second;
            dfs(it.first, t, node);
        }
}

void solve_comp(int root)
{
    nodes.clear();
    dfs(root, 0);

    int x = root;

    for(auto i : nodes)
        if(dist[0][x] < dist[0][i]) x = i;

    dfs(x, 1);

    int y = x;
    for(auto i : nodes)
        if(dist[1][y] < dist[1][i]) y = i;

    dfs(y, 2);

    int best = 1e9;

    for(auto i : nodes)
        if(dist[1][i] + dist[2][i] == dist[1][y])
            best = min(best, max(dist[1][i], dist[2][i]));

    dia.push_back(dist[1][y]);
    mn.push_back(best);
}

int travelTime(int n, int m, int L, int A[], int B[], int T[])
{
    int ans = 0;
    int i;

    for(i=0; i<m; ++i)
    {
        v[A[i]].push_back({B[i], T[i]});
        v[B[i]].push_back({A[i], T[i]});
    }

    for(i=0; i<n; ++i)
        if(!used[i]) solve_comp(i);

    for(auto it : dia)
        ans = max(ans, it);

    sort(mn.begin(), mn.end());
    reverse(mn.begin(), mn.end());

    if(mn.size() >= 2)
        ans = max(ans, mn[0] + mn[1] + L);

    if(mn.size() >= 3)
        ans = max(ans, mn[1] + mn[2] + 2 * L);

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 68 ms 15168 KB Output is correct
2 Correct 67 ms 15232 KB Output is correct
3 Correct 48 ms 11124 KB Output is correct
4 Correct 14 ms 4604 KB Output is correct
5 Correct 12 ms 3704 KB Output is correct
6 Correct 21 ms 5544 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 38 ms 7160 KB Output is correct
9 Correct 46 ms 9064 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 70 ms 11004 KB Output is correct
12 Correct 119 ms 13084 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 15168 KB Output is correct
2 Correct 67 ms 15232 KB Output is correct
3 Correct 48 ms 11124 KB Output is correct
4 Correct 14 ms 4604 KB Output is correct
5 Correct 12 ms 3704 KB Output is correct
6 Correct 21 ms 5544 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 38 ms 7160 KB Output is correct
9 Correct 46 ms 9064 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 70 ms 11004 KB Output is correct
12 Correct 119 ms 13084 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 5 ms 2680 KB Output is correct
15 Correct 4 ms 2684 KB Output is correct
16 Correct 4 ms 2680 KB Output is correct
17 Correct 5 ms 2680 KB Output is correct
18 Correct 5 ms 2680 KB Output is correct
19 Correct 4 ms 2680 KB Output is correct
20 Correct 7 ms 2680 KB Output is correct
21 Correct 5 ms 2680 KB Output is correct
22 Correct 5 ms 2680 KB Output is correct
23 Correct 5 ms 2680 KB Output is correct
24 Correct 5 ms 2808 KB Output is correct
25 Correct 4 ms 2680 KB Output is correct
26 Correct 4 ms 2652 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Correct 4 ms 2680 KB Output is correct
29 Correct 4 ms 2680 KB Output is correct
30 Correct 5 ms 2680 KB Output is correct
31 Correct 4 ms 2680 KB Output is correct
32 Correct 4 ms 2680 KB Output is correct
33 Correct 4 ms 2712 KB Output is correct
34 Correct 4 ms 2680 KB Output is correct
35 Correct 4 ms 2680 KB Output is correct
36 Correct 4 ms 2680 KB Output is correct
37 Correct 4 ms 2680 KB Output is correct
38 Correct 4 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 15168 KB Output is correct
2 Correct 67 ms 15232 KB Output is correct
3 Correct 48 ms 11124 KB Output is correct
4 Correct 14 ms 4604 KB Output is correct
5 Correct 12 ms 3704 KB Output is correct
6 Correct 21 ms 5544 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 38 ms 7160 KB Output is correct
9 Correct 46 ms 9064 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 70 ms 11004 KB Output is correct
12 Correct 119 ms 13084 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 5 ms 2680 KB Output is correct
15 Correct 4 ms 2684 KB Output is correct
16 Correct 4 ms 2680 KB Output is correct
17 Correct 5 ms 2680 KB Output is correct
18 Correct 5 ms 2680 KB Output is correct
19 Correct 4 ms 2680 KB Output is correct
20 Correct 7 ms 2680 KB Output is correct
21 Correct 5 ms 2680 KB Output is correct
22 Correct 5 ms 2680 KB Output is correct
23 Correct 5 ms 2680 KB Output is correct
24 Correct 5 ms 2808 KB Output is correct
25 Correct 4 ms 2680 KB Output is correct
26 Correct 4 ms 2652 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Correct 4 ms 2680 KB Output is correct
29 Correct 4 ms 2680 KB Output is correct
30 Correct 5 ms 2680 KB Output is correct
31 Correct 4 ms 2680 KB Output is correct
32 Correct 4 ms 2680 KB Output is correct
33 Correct 4 ms 2712 KB Output is correct
34 Correct 4 ms 2680 KB Output is correct
35 Correct 4 ms 2680 KB Output is correct
36 Correct 4 ms 2680 KB Output is correct
37 Correct 4 ms 2680 KB Output is correct
38 Correct 4 ms 2680 KB Output is correct
39 Correct 69 ms 15348 KB Output is correct
40 Correct 72 ms 15224 KB Output is correct
41 Correct 48 ms 11196 KB Output is correct
42 Correct 14 ms 4600 KB Output is correct
43 Correct 4 ms 2680 KB Output is correct
44 Correct 4 ms 2680 KB Output is correct
45 Correct 4 ms 2680 KB Output is correct
46 Correct 4 ms 2680 KB Output is correct
47 Correct 4 ms 2680 KB Output is correct
48 Correct 4 ms 2680 KB Output is correct
49 Correct 4 ms 2680 KB Output is correct
50 Correct 4 ms 2684 KB Output is correct
51 Correct 4 ms 2680 KB Output is correct
52 Correct 4 ms 2680 KB Output is correct
53 Correct 4 ms 2680 KB Output is correct
54 Correct 4 ms 2680 KB Output is correct
55 Correct 4 ms 2680 KB Output is correct
56 Correct 4 ms 2680 KB Output is correct
57 Correct 86 ms 10864 KB Output is correct
58 Correct 90 ms 10840 KB Output is correct
59 Correct 118 ms 10960 KB Output is correct
60 Correct 99 ms 10868 KB Output is correct
61 Correct 104 ms 10968 KB Output is correct
62 Correct 119 ms 10872 KB Output is correct
63 Correct 83 ms 10740 KB Output is correct
64 Incorrect 71 ms 10104 KB Output isn't correct
65 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 7412 KB Output is correct
2 Correct 33 ms 7352 KB Output is correct
3 Correct 33 ms 7288 KB Output is correct
4 Correct 42 ms 7316 KB Output is correct
5 Correct 33 ms 7360 KB Output is correct
6 Correct 34 ms 7920 KB Output is correct
7 Correct 33 ms 7668 KB Output is correct
8 Correct 37 ms 7284 KB Output is correct
9 Correct 35 ms 7156 KB Output is correct
10 Correct 34 ms 7460 KB Output is correct
11 Correct 4 ms 2680 KB Output is correct
12 Correct 11 ms 4760 KB Output is correct
13 Correct 11 ms 4960 KB Output is correct
14 Correct 11 ms 4792 KB Output is correct
15 Correct 11 ms 4760 KB Output is correct
16 Correct 11 ms 4600 KB Output is correct
17 Correct 10 ms 4004 KB Output is correct
18 Correct 11 ms 4972 KB Output is correct
19 Correct 11 ms 4716 KB Output is correct
20 Correct 4 ms 2680 KB Output is correct
21 Correct 4 ms 2680 KB Output is correct
22 Correct 4 ms 2808 KB Output is correct
23 Correct 11 ms 4616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 15168 KB Output is correct
2 Correct 67 ms 15232 KB Output is correct
3 Correct 48 ms 11124 KB Output is correct
4 Correct 14 ms 4604 KB Output is correct
5 Correct 12 ms 3704 KB Output is correct
6 Correct 21 ms 5544 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 38 ms 7160 KB Output is correct
9 Correct 46 ms 9064 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 70 ms 11004 KB Output is correct
12 Correct 119 ms 13084 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 4 ms 2808 KB Output is correct
15 Correct 5 ms 2808 KB Output is correct
16 Correct 6 ms 2936 KB Output is correct
17 Correct 5 ms 2808 KB Output is correct
18 Correct 5 ms 2808 KB Output is correct
19 Correct 6 ms 2936 KB Output is correct
20 Correct 5 ms 2808 KB Output is correct
21 Correct 5 ms 2936 KB Output is correct
22 Correct 6 ms 2936 KB Output is correct
23 Correct 4 ms 2684 KB Output is correct
24 Correct 4 ms 2680 KB Output is correct
25 Correct 4 ms 2680 KB Output is correct
26 Correct 4 ms 2680 KB Output is correct
27 Correct 4 ms 2744 KB Output is correct
28 Correct 4 ms 2680 KB Output is correct
29 Correct 4 ms 2680 KB Output is correct
30 Correct 4 ms 2680 KB Output is correct
31 Correct 4 ms 2680 KB Output is correct
32 Correct 4 ms 2680 KB Output is correct
33 Correct 4 ms 2680 KB Output is correct
34 Correct 4 ms 2680 KB Output is correct
35 Correct 4 ms 2680 KB Output is correct
36 Correct 4 ms 2684 KB Output is correct
37 Correct 4 ms 2680 KB Output is correct
38 Correct 4 ms 2680 KB Output is correct
39 Correct 4 ms 2680 KB Output is correct
40 Correct 5 ms 2680 KB Output is correct
41 Correct 4 ms 2680 KB Output is correct
42 Correct 6 ms 3064 KB Output is correct
43 Correct 6 ms 3064 KB Output is correct
44 Correct 5 ms 2936 KB Output is correct
45 Correct 5 ms 2780 KB Output is correct
46 Correct 6 ms 2936 KB Output is correct
47 Correct 6 ms 2936 KB Output is correct
48 Correct 5 ms 2808 KB Output is correct
49 Correct 5 ms 2808 KB Output is correct
50 Correct 6 ms 2936 KB Output is correct
51 Correct 6 ms 2936 KB Output is correct
52 Correct 4 ms 2820 KB Output is correct
53 Correct 5 ms 2936 KB Output is correct
54 Correct 6 ms 2936 KB Output is correct
55 Correct 6 ms 2936 KB Output is correct
56 Correct 5 ms 2936 KB Output is correct
57 Correct 6 ms 2836 KB Output is correct
58 Correct 5 ms 2808 KB Output is correct
59 Correct 5 ms 2808 KB Output is correct
60 Correct 6 ms 2980 KB Output is correct
61 Correct 6 ms 2936 KB Output is correct
62 Correct 6 ms 2936 KB Output is correct
63 Correct 6 ms 2932 KB Output is correct
64 Correct 6 ms 2940 KB Output is correct
65 Correct 6 ms 2936 KB Output is correct
66 Incorrect 5 ms 2808 KB Output isn't correct
67 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 68 ms 15168 KB Output is correct
2 Correct 67 ms 15232 KB Output is correct
3 Correct 48 ms 11124 KB Output is correct
4 Correct 14 ms 4604 KB Output is correct
5 Correct 12 ms 3704 KB Output is correct
6 Correct 21 ms 5544 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 38 ms 7160 KB Output is correct
9 Correct 46 ms 9064 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
11 Correct 70 ms 11004 KB Output is correct
12 Correct 119 ms 13084 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 5 ms 2680 KB Output is correct
15 Correct 4 ms 2684 KB Output is correct
16 Correct 4 ms 2680 KB Output is correct
17 Correct 5 ms 2680 KB Output is correct
18 Correct 5 ms 2680 KB Output is correct
19 Correct 4 ms 2680 KB Output is correct
20 Correct 7 ms 2680 KB Output is correct
21 Correct 5 ms 2680 KB Output is correct
22 Correct 5 ms 2680 KB Output is correct
23 Correct 5 ms 2680 KB Output is correct
24 Correct 5 ms 2808 KB Output is correct
25 Correct 4 ms 2680 KB Output is correct
26 Correct 4 ms 2652 KB Output is correct
27 Correct 4 ms 2680 KB Output is correct
28 Correct 4 ms 2680 KB Output is correct
29 Correct 4 ms 2680 KB Output is correct
30 Correct 5 ms 2680 KB Output is correct
31 Correct 4 ms 2680 KB Output is correct
32 Correct 4 ms 2680 KB Output is correct
33 Correct 4 ms 2712 KB Output is correct
34 Correct 4 ms 2680 KB Output is correct
35 Correct 4 ms 2680 KB Output is correct
36 Correct 4 ms 2680 KB Output is correct
37 Correct 4 ms 2680 KB Output is correct
38 Correct 4 ms 2680 KB Output is correct
39 Correct 69 ms 15348 KB Output is correct
40 Correct 72 ms 15224 KB Output is correct
41 Correct 48 ms 11196 KB Output is correct
42 Correct 14 ms 4600 KB Output is correct
43 Correct 4 ms 2680 KB Output is correct
44 Correct 4 ms 2680 KB Output is correct
45 Correct 4 ms 2680 KB Output is correct
46 Correct 4 ms 2680 KB Output is correct
47 Correct 4 ms 2680 KB Output is correct
48 Correct 4 ms 2680 KB Output is correct
49 Correct 4 ms 2680 KB Output is correct
50 Correct 4 ms 2684 KB Output is correct
51 Correct 4 ms 2680 KB Output is correct
52 Correct 4 ms 2680 KB Output is correct
53 Correct 4 ms 2680 KB Output is correct
54 Correct 4 ms 2680 KB Output is correct
55 Correct 4 ms 2680 KB Output is correct
56 Correct 4 ms 2680 KB Output is correct
57 Correct 86 ms 10864 KB Output is correct
58 Correct 90 ms 10840 KB Output is correct
59 Correct 118 ms 10960 KB Output is correct
60 Correct 99 ms 10868 KB Output is correct
61 Correct 104 ms 10968 KB Output is correct
62 Correct 119 ms 10872 KB Output is correct
63 Correct 83 ms 10740 KB Output is correct
64 Incorrect 71 ms 10104 KB Output isn't correct
65 Halted 0 ms 0 KB -