Submission #1025922

# Submission time Handle Problem Language Result Execution time Memory
1025922 2024-07-17T11:17:07 Z onbert Dreaming (IOI13_dreaming) C++17
47 / 100
52 ms 14452 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5, INF = 1e9;
int n, m, l;
vector<pair<int,int>> adj[maxn];
int dist[maxn];
vector<int> cur;

void dfs(int u) {
    cur.push_back(u);
    for (auto [v, w]:adj[u]) if (dist[v] == -1) {
        dist[v] = dist[u] + w;
        dfs(v);
    }
}

int finish;
vector<int> track;
bool done;
void dfs2(int u) {
    if (!done) track.push_back(u);
    if (u==finish) done = true;
    for (auto [v, w]:adj[u]) if (dist[v] == -1) {
        dist[v] = dist[u] + w;
        dfs2(v);
    }
    if (!done) track.pop_back();
}

int32_t travelTime(int32_t N, int32_t M, int32_t L, int32_t A[], int32_t B[], int32_t 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]});
    }
    for (int i=0;i<n;i++) dist[i] = -1;
    int32_t ans2 = 0;
    vector<int> vals;
    for (int i=0;i<n;i++) if (dist[i] == -1) {
        cur.clear();
        dist[i] = 0;
        dfs(i);
        int start = i;
        for (int j:cur) if (dist[j] > dist[start]) start = j;
        for (int j:cur) dist[j] = -1;
        cur.clear();
        dist[start] = 0;
        dfs(start);
        finish = start;
        for (int j:cur) if (dist[j] > dist[finish]) finish = j;
        ans2 = max(dist[finish], ans2);
        for (int j:cur) dist[j] = -1;
        dist[start] = 0, done = false;
        track.clear();
        dfs2(start);
        int cost = INF;
        for (int j:track) cost = min(max(dist[finish]-dist[j], dist[j]), cost);
        vals.push_back(cost);
    }
    sort(vals.rbegin(), vals.rend());
    int ans1 = 0;
    if (vals.size() >= 2) ans1 = l + vals[0] + vals[1];
    return max(ans1, ans2);
}

// signed main() {
//     ios::sync_with_stdio(0); cin.tie(0);
//     int32_t n, m, l;
//     cin >> n >> m >> l;
//     int32_t a[m], b[m], t[m];
//     for (int i=0;i<m;i++) cin >> a[i] >> b[i] >> t[i];
//     cout << travelTime(n, m, l, a, b, t) << endl;
// }
# Verdict Execution time Memory Grader output
1 Correct 33 ms 13524 KB Output is correct
2 Correct 36 ms 13516 KB Output is correct
3 Correct 23 ms 10328 KB Output is correct
4 Correct 6 ms 5464 KB Output is correct
5 Correct 5 ms 4956 KB Output is correct
6 Correct 10 ms 6232 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 19 ms 7516 KB Output is correct
9 Correct 24 ms 8916 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 33 ms 10196 KB Output is correct
12 Correct 42 ms 11736 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3932 KB Output is correct
2 Correct 1 ms 4188 KB Output is correct
3 Correct 1 ms 4188 KB Output is correct
4 Correct 1 ms 3932 KB Output is correct
5 Correct 2 ms 4124 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 1 ms 4188 KB Output is correct
8 Correct 2 ms 3928 KB Output is correct
9 Correct 1 ms 3932 KB Output is correct
10 Correct 1 ms 3932 KB Output is correct
11 Correct 1 ms 3932 KB Output is correct
12 Correct 1 ms 4184 KB Output is correct
13 Correct 2 ms 3928 KB Output is correct
14 Correct 1 ms 4188 KB Output is correct
15 Correct 1 ms 3932 KB Output is correct
16 Correct 1 ms 4188 KB Output is correct
17 Correct 1 ms 3932 KB Output is correct
18 Correct 1 ms 3932 KB Output is correct
19 Correct 1 ms 4188 KB Output is correct
20 Correct 1 ms 4188 KB Output is correct
21 Correct 1 ms 3932 KB Output is correct
22 Correct 1 ms 3932 KB Output is correct
23 Correct 1 ms 4188 KB Output is correct
24 Correct 1 ms 3932 KB Output is correct
25 Correct 1 ms 3932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 13524 KB Output is correct
2 Correct 36 ms 13516 KB Output is correct
3 Correct 23 ms 10328 KB Output is correct
4 Correct 6 ms 5464 KB Output is correct
5 Correct 5 ms 4956 KB Output is correct
6 Correct 10 ms 6232 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 19 ms 7516 KB Output is correct
9 Correct 24 ms 8916 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 33 ms 10196 KB Output is correct
12 Correct 42 ms 11736 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 2 ms 3932 KB Output is correct
15 Correct 1 ms 4188 KB Output is correct
16 Correct 1 ms 4188 KB Output is correct
17 Correct 1 ms 3932 KB Output is correct
18 Correct 2 ms 4124 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 1 ms 4188 KB Output is correct
21 Correct 2 ms 3928 KB Output is correct
22 Correct 1 ms 3932 KB Output is correct
23 Correct 1 ms 3932 KB Output is correct
24 Correct 1 ms 3932 KB Output is correct
25 Correct 1 ms 4184 KB Output is correct
26 Correct 2 ms 3928 KB Output is correct
27 Correct 1 ms 4188 KB Output is correct
28 Correct 1 ms 3932 KB Output is correct
29 Correct 1 ms 4188 KB Output is correct
30 Correct 1 ms 3932 KB Output is correct
31 Correct 1 ms 3932 KB Output is correct
32 Correct 1 ms 4188 KB Output is correct
33 Correct 1 ms 4188 KB Output is correct
34 Correct 1 ms 3932 KB Output is correct
35 Correct 1 ms 3932 KB Output is correct
36 Correct 1 ms 4188 KB Output is correct
37 Correct 1 ms 3932 KB Output is correct
38 Correct 1 ms 3932 KB Output is correct
39 Correct 32 ms 13520 KB Output is correct
40 Correct 38 ms 13520 KB Output is correct
41 Correct 26 ms 10316 KB Output is correct
42 Correct 6 ms 5468 KB Output is correct
43 Correct 1 ms 4188 KB Output is correct
44 Correct 1 ms 4188 KB Output is correct
45 Correct 1 ms 3932 KB Output is correct
46 Correct 1 ms 4188 KB Output is correct
47 Correct 1 ms 4188 KB Output is correct
48 Correct 1 ms 4188 KB Output is correct
49 Correct 1 ms 3932 KB Output is correct
50 Correct 1 ms 4184 KB Output is correct
51 Correct 1 ms 4012 KB Output is correct
52 Correct 1 ms 3932 KB Output is correct
53 Correct 2 ms 4188 KB Output is correct
54 Correct 1 ms 4188 KB Output is correct
55 Correct 1 ms 3932 KB Output is correct
56 Correct 1 ms 4176 KB Output is correct
57 Correct 39 ms 9880 KB Output is correct
58 Correct 39 ms 9704 KB Output is correct
59 Correct 52 ms 9900 KB Output is correct
60 Correct 42 ms 9688 KB Output is correct
61 Correct 42 ms 9940 KB Output is correct
62 Correct 42 ms 9808 KB Output is correct
63 Correct 36 ms 9692 KB Output is correct
64 Correct 38 ms 9684 KB Output is correct
65 Correct 37 ms 9940 KB Output is correct
66 Correct 35 ms 9768 KB Output is correct
67 Correct 47 ms 9748 KB Output is correct
68 Correct 40 ms 9932 KB Output is correct
69 Correct 42 ms 9808 KB Output is correct
70 Correct 42 ms 9808 KB Output is correct
71 Correct 2 ms 3928 KB Output is correct
72 Correct 2 ms 4188 KB Output is correct
73 Correct 2 ms 4188 KB Output is correct
74 Correct 2 ms 4188 KB Output is correct
75 Correct 3 ms 4188 KB Output is correct
76 Correct 3 ms 4188 KB Output is correct
77 Correct 2 ms 4188 KB Output is correct
78 Correct 3 ms 4196 KB Output is correct
79 Correct 2 ms 4184 KB Output is correct
80 Correct 45 ms 9932 KB Output is correct
81 Correct 45 ms 9704 KB Output is correct
82 Correct 39 ms 9944 KB Output is correct
83 Correct 45 ms 9936 KB Output is correct
84 Correct 3 ms 4184 KB Output is correct
85 Correct 2 ms 4188 KB Output is correct
86 Correct 2 ms 4188 KB Output is correct
87 Correct 2 ms 4188 KB Output is correct
88 Correct 2 ms 4188 KB Output is correct
89 Correct 2 ms 4188 KB Output is correct
90 Correct 2 ms 4188 KB Output is correct
91 Correct 2 ms 4188 KB Output is correct
92 Correct 3 ms 4188 KB Output is correct
93 Correct 2 ms 4188 KB Output is correct
94 Correct 1 ms 3932 KB Output is correct
95 Correct 2 ms 4184 KB Output is correct
96 Correct 1 ms 4184 KB Output is correct
97 Correct 1 ms 3980 KB Output is correct
98 Correct 1 ms 4188 KB Output is correct
99 Correct 1 ms 4184 KB Output is correct
100 Correct 1 ms 3932 KB Output is correct
101 Correct 1 ms 4188 KB Output is correct
102 Correct 1 ms 4188 KB Output is correct
103 Correct 2 ms 4188 KB Output is correct
104 Correct 8 ms 4960 KB Output is correct
105 Correct 10 ms 6236 KB Output is correct
106 Correct 2 ms 4188 KB Output is correct
107 Correct 19 ms 7592 KB Output is correct
108 Correct 25 ms 8912 KB Output is correct
109 Correct 1 ms 4188 KB Output is correct
110 Correct 32 ms 10116 KB Output is correct
111 Correct 38 ms 11732 KB Output is correct
112 Correct 2 ms 4184 KB Output is correct
113 Correct 49 ms 14452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 7004 KB Output is correct
2 Incorrect 14 ms 7072 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3932 KB Output is correct
2 Correct 1 ms 4188 KB Output is correct
3 Correct 1 ms 4188 KB Output is correct
4 Correct 1 ms 3932 KB Output is correct
5 Correct 2 ms 4124 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 1 ms 4188 KB Output is correct
8 Correct 2 ms 3928 KB Output is correct
9 Correct 1 ms 3932 KB Output is correct
10 Correct 1 ms 3932 KB Output is correct
11 Correct 1 ms 3932 KB Output is correct
12 Correct 1 ms 4184 KB Output is correct
13 Correct 2 ms 3928 KB Output is correct
14 Correct 1 ms 4188 KB Output is correct
15 Correct 1 ms 3932 KB Output is correct
16 Correct 1 ms 4188 KB Output is correct
17 Correct 1 ms 3932 KB Output is correct
18 Correct 1 ms 3932 KB Output is correct
19 Correct 1 ms 4188 KB Output is correct
20 Correct 1 ms 4188 KB Output is correct
21 Correct 1 ms 3932 KB Output is correct
22 Correct 1 ms 3932 KB Output is correct
23 Correct 1 ms 4188 KB Output is correct
24 Correct 1 ms 3932 KB Output is correct
25 Correct 1 ms 3932 KB Output is correct
26 Correct 2 ms 4184 KB Output is correct
27 Correct 2 ms 4188 KB Output is correct
28 Correct 2 ms 4188 KB Output is correct
29 Correct 2 ms 4184 KB Output is correct
30 Correct 2 ms 4188 KB Output is correct
31 Correct 3 ms 4188 KB Output is correct
32 Incorrect 2 ms 4188 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 13524 KB Output is correct
2 Correct 36 ms 13516 KB Output is correct
3 Correct 23 ms 10328 KB Output is correct
4 Correct 6 ms 5464 KB Output is correct
5 Correct 5 ms 4956 KB Output is correct
6 Correct 10 ms 6232 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 19 ms 7516 KB Output is correct
9 Correct 24 ms 8916 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 33 ms 10196 KB Output is correct
12 Correct 42 ms 11736 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 2 ms 3932 KB Output is correct
15 Correct 1 ms 4188 KB Output is correct
16 Correct 1 ms 4188 KB Output is correct
17 Correct 1 ms 3932 KB Output is correct
18 Correct 2 ms 4124 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 1 ms 4188 KB Output is correct
21 Correct 2 ms 3928 KB Output is correct
22 Correct 1 ms 3932 KB Output is correct
23 Correct 1 ms 3932 KB Output is correct
24 Correct 1 ms 3932 KB Output is correct
25 Correct 1 ms 4184 KB Output is correct
26 Correct 2 ms 3928 KB Output is correct
27 Correct 1 ms 4188 KB Output is correct
28 Correct 1 ms 3932 KB Output is correct
29 Correct 1 ms 4188 KB Output is correct
30 Correct 1 ms 3932 KB Output is correct
31 Correct 1 ms 3932 KB Output is correct
32 Correct 1 ms 4188 KB Output is correct
33 Correct 1 ms 4188 KB Output is correct
34 Correct 1 ms 3932 KB Output is correct
35 Correct 1 ms 3932 KB Output is correct
36 Correct 1 ms 4188 KB Output is correct
37 Correct 1 ms 3932 KB Output is correct
38 Correct 1 ms 3932 KB Output is correct
39 Correct 32 ms 13520 KB Output is correct
40 Correct 38 ms 13520 KB Output is correct
41 Correct 26 ms 10316 KB Output is correct
42 Correct 6 ms 5468 KB Output is correct
43 Correct 1 ms 4188 KB Output is correct
44 Correct 1 ms 4188 KB Output is correct
45 Correct 1 ms 3932 KB Output is correct
46 Correct 1 ms 4188 KB Output is correct
47 Correct 1 ms 4188 KB Output is correct
48 Correct 1 ms 4188 KB Output is correct
49 Correct 1 ms 3932 KB Output is correct
50 Correct 1 ms 4184 KB Output is correct
51 Correct 1 ms 4012 KB Output is correct
52 Correct 1 ms 3932 KB Output is correct
53 Correct 2 ms 4188 KB Output is correct
54 Correct 1 ms 4188 KB Output is correct
55 Correct 1 ms 3932 KB Output is correct
56 Correct 1 ms 4176 KB Output is correct
57 Correct 39 ms 9880 KB Output is correct
58 Correct 39 ms 9704 KB Output is correct
59 Correct 52 ms 9900 KB Output is correct
60 Correct 42 ms 9688 KB Output is correct
61 Correct 42 ms 9940 KB Output is correct
62 Correct 42 ms 9808 KB Output is correct
63 Correct 36 ms 9692 KB Output is correct
64 Correct 38 ms 9684 KB Output is correct
65 Correct 37 ms 9940 KB Output is correct
66 Correct 35 ms 9768 KB Output is correct
67 Correct 47 ms 9748 KB Output is correct
68 Correct 40 ms 9932 KB Output is correct
69 Correct 42 ms 9808 KB Output is correct
70 Correct 42 ms 9808 KB Output is correct
71 Correct 2 ms 3928 KB Output is correct
72 Correct 2 ms 4188 KB Output is correct
73 Correct 2 ms 4188 KB Output is correct
74 Correct 2 ms 4188 KB Output is correct
75 Correct 3 ms 4188 KB Output is correct
76 Correct 3 ms 4188 KB Output is correct
77 Correct 2 ms 4188 KB Output is correct
78 Correct 3 ms 4196 KB Output is correct
79 Correct 2 ms 4184 KB Output is correct
80 Correct 45 ms 9932 KB Output is correct
81 Correct 45 ms 9704 KB Output is correct
82 Correct 39 ms 9944 KB Output is correct
83 Correct 45 ms 9936 KB Output is correct
84 Correct 3 ms 4184 KB Output is correct
85 Correct 2 ms 4188 KB Output is correct
86 Correct 2 ms 4188 KB Output is correct
87 Correct 2 ms 4188 KB Output is correct
88 Correct 2 ms 4188 KB Output is correct
89 Correct 2 ms 4188 KB Output is correct
90 Correct 2 ms 4188 KB Output is correct
91 Correct 2 ms 4188 KB Output is correct
92 Correct 3 ms 4188 KB Output is correct
93 Correct 2 ms 4188 KB Output is correct
94 Correct 1 ms 3932 KB Output is correct
95 Correct 2 ms 4184 KB Output is correct
96 Correct 1 ms 4184 KB Output is correct
97 Correct 1 ms 3980 KB Output is correct
98 Correct 1 ms 4188 KB Output is correct
99 Correct 1 ms 4184 KB Output is correct
100 Correct 1 ms 3932 KB Output is correct
101 Correct 1 ms 4188 KB Output is correct
102 Correct 1 ms 4188 KB Output is correct
103 Correct 2 ms 4188 KB Output is correct
104 Correct 8 ms 4960 KB Output is correct
105 Correct 10 ms 6236 KB Output is correct
106 Correct 2 ms 4188 KB Output is correct
107 Correct 19 ms 7592 KB Output is correct
108 Correct 25 ms 8912 KB Output is correct
109 Correct 1 ms 4188 KB Output is correct
110 Correct 32 ms 10116 KB Output is correct
111 Correct 38 ms 11732 KB Output is correct
112 Correct 2 ms 4184 KB Output is correct
113 Correct 49 ms 14452 KB Output is correct
114 Correct 14 ms 7004 KB Output is correct
115 Incorrect 14 ms 7072 KB Output isn't correct
116 Halted 0 ms 0 KB -