Submission #156340

# Submission time Handle Problem Language Result Execution time Memory
156340 2019-10-05T08:55:27 Z Alexa2001 Dreaming (IOI13_dreaming) C++17
54 / 100
94 ms 13964 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 67 ms 13940 KB Output is correct
2 Correct 70 ms 13936 KB Output is correct
3 Correct 46 ms 10228 KB Output is correct
4 Correct 13 ms 4344 KB Output is correct
5 Correct 11 ms 3576 KB Output is correct
6 Correct 21 ms 5240 KB Output is correct
7 Correct 4 ms 2808 KB Output is correct
8 Correct 37 ms 6648 KB Output is correct
9 Correct 45 ms 8440 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 62 ms 9848 KB Output is correct
12 Correct 74 ms 11884 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 13940 KB Output is correct
2 Correct 70 ms 13936 KB Output is correct
3 Correct 46 ms 10228 KB Output is correct
4 Correct 13 ms 4344 KB Output is correct
5 Correct 11 ms 3576 KB Output is correct
6 Correct 21 ms 5240 KB Output is correct
7 Correct 4 ms 2808 KB Output is correct
8 Correct 37 ms 6648 KB Output is correct
9 Correct 45 ms 8440 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 62 ms 9848 KB Output is correct
12 Correct 74 ms 11884 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 4 ms 2680 KB Output is correct
15 Correct 4 ms 2808 KB Output is correct
16 Correct 4 ms 2680 KB Output is correct
17 Correct 4 ms 2680 KB Output is correct
18 Correct 4 ms 2680 KB Output is correct
19 Correct 4 ms 2680 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 2680 KB Output is correct
23 Correct 4 ms 2680 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 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 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 2684 KB Output is correct
36 Correct 5 ms 2680 KB Output is correct
37 Correct 4 ms 2680 KB Output is correct
38 Correct 5 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 13940 KB Output is correct
2 Correct 70 ms 13936 KB Output is correct
3 Correct 46 ms 10228 KB Output is correct
4 Correct 13 ms 4344 KB Output is correct
5 Correct 11 ms 3576 KB Output is correct
6 Correct 21 ms 5240 KB Output is correct
7 Correct 4 ms 2808 KB Output is correct
8 Correct 37 ms 6648 KB Output is correct
9 Correct 45 ms 8440 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 62 ms 9848 KB Output is correct
12 Correct 74 ms 11884 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 4 ms 2680 KB Output is correct
15 Correct 4 ms 2808 KB Output is correct
16 Correct 4 ms 2680 KB Output is correct
17 Correct 4 ms 2680 KB Output is correct
18 Correct 4 ms 2680 KB Output is correct
19 Correct 4 ms 2680 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 2680 KB Output is correct
23 Correct 4 ms 2680 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 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 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 2684 KB Output is correct
36 Correct 5 ms 2680 KB Output is correct
37 Correct 4 ms 2680 KB Output is correct
38 Correct 5 ms 2680 KB Output is correct
39 Correct 67 ms 13936 KB Output is correct
40 Correct 74 ms 13964 KB Output is correct
41 Correct 47 ms 10184 KB Output is correct
42 Correct 13 ms 4344 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 2684 KB Output is correct
57 Correct 87 ms 9584 KB Output is correct
58 Correct 89 ms 9516 KB Output is correct
59 Correct 90 ms 9456 KB Output is correct
60 Correct 87 ms 9384 KB Output is correct
61 Correct 84 ms 9456 KB Output is correct
62 Correct 94 ms 9464 KB Output is correct
63 Correct 81 ms 9332 KB Output is correct
64 Incorrect 69 ms 8696 KB Output isn't correct
65 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 6900 KB Output is correct
2 Correct 33 ms 6940 KB Output is correct
3 Correct 31 ms 6900 KB Output is correct
4 Correct 33 ms 6900 KB Output is correct
5 Correct 32 ms 6904 KB Output is correct
6 Correct 34 ms 7412 KB Output is correct
7 Correct 36 ms 7108 KB Output is correct
8 Correct 35 ms 6828 KB Output is correct
9 Correct 33 ms 6772 KB Output is correct
10 Correct 35 ms 6948 KB Output is correct
11 Correct 4 ms 2680 KB Output is correct
12 Correct 12 ms 4756 KB Output is correct
13 Correct 11 ms 4756 KB Output is correct
14 Correct 11 ms 4672 KB Output is correct
15 Correct 11 ms 4756 KB Output is correct
16 Correct 11 ms 4632 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 4640 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 2756 KB Output is correct
23 Correct 12 ms 4612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 13940 KB Output is correct
2 Correct 70 ms 13936 KB Output is correct
3 Correct 46 ms 10228 KB Output is correct
4 Correct 13 ms 4344 KB Output is correct
5 Correct 11 ms 3576 KB Output is correct
6 Correct 21 ms 5240 KB Output is correct
7 Correct 4 ms 2808 KB Output is correct
8 Correct 37 ms 6648 KB Output is correct
9 Correct 45 ms 8440 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 62 ms 9848 KB Output is correct
12 Correct 74 ms 11884 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 5 ms 2808 KB Output is correct
15 Correct 5 ms 2808 KB Output is correct
16 Correct 5 ms 2936 KB Output is correct
17 Correct 4 ms 2808 KB Output is correct
18 Correct 5 ms 2808 KB Output is correct
19 Correct 5 ms 2936 KB Output is correct
20 Correct 5 ms 2808 KB Output is correct
21 Correct 5 ms 2808 KB Output is correct
22 Correct 6 ms 2936 KB Output is correct
23 Correct 4 ms 2680 KB Output is correct
24 Correct 5 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 2680 KB Output is correct
28 Correct 4 ms 2684 KB Output is correct
29 Correct 4 ms 2808 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 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 5 ms 2680 KB Output is correct
40 Correct 4 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 4 ms 2808 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 4 ms 2808 KB Output is correct
50 Correct 6 ms 2940 KB Output is correct
51 Correct 6 ms 2936 KB Output is correct
52 Correct 4 ms 2808 KB Output is correct
53 Correct 5 ms 2808 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 5 ms 2936 KB Output is correct
58 Correct 5 ms 2808 KB Output is correct
59 Correct 5 ms 2760 KB Output is correct
60 Correct 7 ms 2940 KB Output is correct
61 Correct 6 ms 2936 KB Output is correct
62 Correct 6 ms 2808 KB Output is correct
63 Correct 6 ms 2808 KB Output is correct
64 Correct 6 ms 2936 KB Output is correct
65 Correct 6 ms 2984 KB Output is correct
66 Correct 5 ms 2808 KB Output is correct
67 Correct 5 ms 2808 KB Output is correct
68 Correct 4 ms 2808 KB Output is correct
69 Correct 4 ms 2808 KB Output is correct
70 Correct 6 ms 2844 KB Output is correct
71 Correct 6 ms 2936 KB Output is correct
72 Correct 5 ms 2808 KB Output is correct
73 Correct 4 ms 2808 KB Output is correct
74 Correct 5 ms 2936 KB Output is correct
75 Correct 6 ms 2936 KB Output is correct
76 Correct 5 ms 2908 KB Output is correct
77 Correct 5 ms 2936 KB Output is correct
78 Correct 5 ms 2812 KB Output is correct
79 Correct 5 ms 2808 KB Output is correct
80 Correct 5 ms 2908 KB Output is correct
81 Correct 5 ms 2928 KB Output is correct
82 Correct 5 ms 2808 KB Output is correct
83 Correct 6 ms 2936 KB Output is correct
84 Correct 6 ms 2936 KB Output is correct
85 Correct 6 ms 2936 KB Output is correct
86 Correct 6 ms 2936 KB Output is correct
87 Correct 6 ms 2936 KB Output is correct
88 Correct 6 ms 2936 KB Output is correct
89 Correct 6 ms 2888 KB Output is correct
90 Correct 4 ms 2680 KB Output is correct
91 Correct 4 ms 2680 KB Output is correct
92 Correct 4 ms 2680 KB Output is correct
93 Correct 4 ms 2680 KB Output is correct
94 Correct 4 ms 2680 KB Output is correct
95 Correct 4 ms 2808 KB Output is correct
96 Correct 4 ms 2756 KB Output is correct
97 Correct 4 ms 2680 KB Output is correct
98 Correct 4 ms 2680 KB Output is correct
99 Correct 4 ms 2680 KB Output is correct
100 Correct 4 ms 2680 KB Output is correct
101 Correct 5 ms 2808 KB Output is correct
102 Correct 4 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 13940 KB Output is correct
2 Correct 70 ms 13936 KB Output is correct
3 Correct 46 ms 10228 KB Output is correct
4 Correct 13 ms 4344 KB Output is correct
5 Correct 11 ms 3576 KB Output is correct
6 Correct 21 ms 5240 KB Output is correct
7 Correct 4 ms 2808 KB Output is correct
8 Correct 37 ms 6648 KB Output is correct
9 Correct 45 ms 8440 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 62 ms 9848 KB Output is correct
12 Correct 74 ms 11884 KB Output is correct
13 Correct 5 ms 2808 KB Output is correct
14 Correct 4 ms 2680 KB Output is correct
15 Correct 4 ms 2808 KB Output is correct
16 Correct 4 ms 2680 KB Output is correct
17 Correct 4 ms 2680 KB Output is correct
18 Correct 4 ms 2680 KB Output is correct
19 Correct 4 ms 2680 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 2680 KB Output is correct
23 Correct 4 ms 2680 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 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 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 2684 KB Output is correct
36 Correct 5 ms 2680 KB Output is correct
37 Correct 4 ms 2680 KB Output is correct
38 Correct 5 ms 2680 KB Output is correct
39 Correct 67 ms 13936 KB Output is correct
40 Correct 74 ms 13964 KB Output is correct
41 Correct 47 ms 10184 KB Output is correct
42 Correct 13 ms 4344 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 2684 KB Output is correct
57 Correct 87 ms 9584 KB Output is correct
58 Correct 89 ms 9516 KB Output is correct
59 Correct 90 ms 9456 KB Output is correct
60 Correct 87 ms 9384 KB Output is correct
61 Correct 84 ms 9456 KB Output is correct
62 Correct 94 ms 9464 KB Output is correct
63 Correct 81 ms 9332 KB Output is correct
64 Incorrect 69 ms 8696 KB Output isn't correct
65 Halted 0 ms 0 KB -