Submission #1004973

# Submission time Handle Problem Language Result Execution time Memory
1004973 2024-06-22T05:25:18 Z The_Samurai Dreaming (IOI13_dreaming) C++17
47 / 100
49 ms 16068 KB
#include "dreaming.h"
#include "bits/stdc++.h"
using namespace std;

int travelTime(int n, int m, int L, int A[], int B[], int T[]) {
    vector<vector<pair<int, int>>> g(n);
    vector<bool> vis(n), vis2(n);
    for (int i = 0; i < m; i++) {
        g[A[i]].emplace_back(B[i], T[i]);
        g[B[i]].emplace_back(A[i], T[i]);
    }
    vector<int> h(n), dist(n), all;
    auto dfs = [&](auto &dfs, int u) -> void {
        all.emplace_back(u);
        vis[u] = true;
        for (auto [v, w]: g[u]) {
            if (vis[v]) continue;
            dfs(dfs, v);
            h[u] = max(h[u], h[v] + w);
        }
    };
    auto dfs2 = [&](auto &dfs2, int u, int came) -> void {
        // cout << '\t' << u << ' ' << came << endl;
        vis2[u] = true;
        int mx1 = 0, mx2 = 0;
        for (auto [v, w]: g[u]) {
            if (vis2[v]) continue;
            if (mx1 < h[v] + w) {
                mx2 = mx1;
                mx1 = h[v] + w;
            } else {
                mx2 = max(mx2, h[v] + w);
            }
        }
        dist[u] = max(came, h[u]);
        for (auto [v, w]: g[u]) {
            if (vis2[v]) continue;
            if (mx1 == h[v] + w) {
                dfs2(dfs2, v, max(came, mx2) + w);
            } else {
                dfs2(dfs2, v, max(came, mx1) + w);
            }
        }
    };
    int mx1 = 0, mx2 = 0, cnt = 0, ans = 0;
    for (int i = 0; i < n; i++) {
        if (vis[i]) continue;
        cnt++;
        dfs(dfs, i);
        dfs2(dfs2, i, 0);
        int mn = 1e9;
        for (int u: all) mn = min(mn, dist[u]);
        for (int u: all) ans = max(ans, dist[u]);
        // for (int u: all) {
        //     cout << u << ' ' << dist[u] << endl;
        // }
        // cout << endl;
        if (mx1 < mn) {
            mx2 = mx1;
            mx1 = mn;
        } else {
            mx2 = max(mx2, mn);
        }
        all.clear();
    }
    if (cnt == 1) return ans;
    return max(mx1 + mx2 + L, ans);
}
# Verdict Execution time Memory Grader output
1 Correct 31 ms 11484 KB Output is correct
2 Correct 35 ms 11192 KB Output is correct
3 Correct 20 ms 9176 KB Output is correct
4 Correct 4 ms 1884 KB Output is correct
5 Correct 3 ms 1372 KB Output is correct
6 Correct 8 ms 2908 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 17 ms 4956 KB Output is correct
9 Correct 20 ms 7528 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 28 ms 8428 KB Output is correct
12 Correct 36 ms 9928 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 11484 KB Output is correct
2 Correct 35 ms 11192 KB Output is correct
3 Correct 20 ms 9176 KB Output is correct
4 Correct 4 ms 1884 KB Output is correct
5 Correct 3 ms 1372 KB Output is correct
6 Correct 8 ms 2908 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 17 ms 4956 KB Output is correct
9 Correct 20 ms 7528 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 28 ms 8428 KB Output is correct
12 Correct 36 ms 9928 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 30 ms 11476 KB Output is correct
40 Correct 31 ms 11228 KB Output is correct
41 Correct 19 ms 9176 KB Output is correct
42 Correct 5 ms 1884 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 45 ms 9400 KB Output is correct
58 Correct 37 ms 9052 KB Output is correct
59 Correct 44 ms 9228 KB Output is correct
60 Correct 34 ms 8920 KB Output is correct
61 Correct 44 ms 9164 KB Output is correct
62 Correct 35 ms 8912 KB Output is correct
63 Correct 40 ms 8920 KB Output is correct
64 Correct 39 ms 8884 KB Output is correct
65 Correct 36 ms 8996 KB Output is correct
66 Correct 36 ms 8916 KB Output is correct
67 Correct 36 ms 9312 KB Output is correct
68 Correct 37 ms 9164 KB Output is correct
69 Correct 37 ms 8920 KB Output is correct
70 Correct 41 ms 8972 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 1 ms 604 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 1 ms 604 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 1 ms 604 KB Output is correct
77 Correct 1 ms 604 KB Output is correct
78 Correct 1 ms 604 KB Output is correct
79 Correct 1 ms 604 KB Output is correct
80 Correct 39 ms 9320 KB Output is correct
81 Correct 43 ms 9188 KB Output is correct
82 Correct 41 ms 9168 KB Output is correct
83 Correct 37 ms 9168 KB Output is correct
84 Correct 1 ms 604 KB Output is correct
85 Correct 1 ms 604 KB Output is correct
86 Correct 1 ms 604 KB Output is correct
87 Correct 1 ms 604 KB Output is correct
88 Correct 1 ms 604 KB Output is correct
89 Correct 1 ms 604 KB Output is correct
90 Correct 1 ms 604 KB Output is correct
91 Correct 1 ms 604 KB Output is correct
92 Correct 1 ms 604 KB Output is correct
93 Correct 2 ms 604 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 0 ms 348 KB Output is correct
98 Correct 1 ms 348 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 0 ms 600 KB Output is correct
101 Correct 0 ms 348 KB Output is correct
102 Correct 0 ms 348 KB Output is correct
103 Correct 0 ms 348 KB Output is correct
104 Correct 4 ms 1368 KB Output is correct
105 Correct 8 ms 2908 KB Output is correct
106 Correct 0 ms 348 KB Output is correct
107 Correct 17 ms 4956 KB Output is correct
108 Correct 21 ms 7388 KB Output is correct
109 Correct 1 ms 348 KB Output is correct
110 Correct 32 ms 8412 KB Output is correct
111 Correct 34 ms 9940 KB Output is correct
112 Correct 1 ms 344 KB Output is correct
113 Correct 49 ms 16068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 5720 KB Output is correct
2 Incorrect 13 ms 5720 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Incorrect 0 ms 348 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 11484 KB Output is correct
2 Correct 35 ms 11192 KB Output is correct
3 Correct 20 ms 9176 KB Output is correct
4 Correct 4 ms 1884 KB Output is correct
5 Correct 3 ms 1372 KB Output is correct
6 Correct 8 ms 2908 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 17 ms 4956 KB Output is correct
9 Correct 20 ms 7528 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 28 ms 8428 KB Output is correct
12 Correct 36 ms 9928 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 30 ms 11476 KB Output is correct
40 Correct 31 ms 11228 KB Output is correct
41 Correct 19 ms 9176 KB Output is correct
42 Correct 5 ms 1884 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 45 ms 9400 KB Output is correct
58 Correct 37 ms 9052 KB Output is correct
59 Correct 44 ms 9228 KB Output is correct
60 Correct 34 ms 8920 KB Output is correct
61 Correct 44 ms 9164 KB Output is correct
62 Correct 35 ms 8912 KB Output is correct
63 Correct 40 ms 8920 KB Output is correct
64 Correct 39 ms 8884 KB Output is correct
65 Correct 36 ms 8996 KB Output is correct
66 Correct 36 ms 8916 KB Output is correct
67 Correct 36 ms 9312 KB Output is correct
68 Correct 37 ms 9164 KB Output is correct
69 Correct 37 ms 8920 KB Output is correct
70 Correct 41 ms 8972 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 1 ms 604 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 1 ms 604 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 1 ms 604 KB Output is correct
77 Correct 1 ms 604 KB Output is correct
78 Correct 1 ms 604 KB Output is correct
79 Correct 1 ms 604 KB Output is correct
80 Correct 39 ms 9320 KB Output is correct
81 Correct 43 ms 9188 KB Output is correct
82 Correct 41 ms 9168 KB Output is correct
83 Correct 37 ms 9168 KB Output is correct
84 Correct 1 ms 604 KB Output is correct
85 Correct 1 ms 604 KB Output is correct
86 Correct 1 ms 604 KB Output is correct
87 Correct 1 ms 604 KB Output is correct
88 Correct 1 ms 604 KB Output is correct
89 Correct 1 ms 604 KB Output is correct
90 Correct 1 ms 604 KB Output is correct
91 Correct 1 ms 604 KB Output is correct
92 Correct 1 ms 604 KB Output is correct
93 Correct 2 ms 604 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 0 ms 348 KB Output is correct
98 Correct 1 ms 348 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 0 ms 600 KB Output is correct
101 Correct 0 ms 348 KB Output is correct
102 Correct 0 ms 348 KB Output is correct
103 Correct 0 ms 348 KB Output is correct
104 Correct 4 ms 1368 KB Output is correct
105 Correct 8 ms 2908 KB Output is correct
106 Correct 0 ms 348 KB Output is correct
107 Correct 17 ms 4956 KB Output is correct
108 Correct 21 ms 7388 KB Output is correct
109 Correct 1 ms 348 KB Output is correct
110 Correct 32 ms 8412 KB Output is correct
111 Correct 34 ms 9940 KB Output is correct
112 Correct 1 ms 344 KB Output is correct
113 Correct 49 ms 16068 KB Output is correct
114 Correct 16 ms 5720 KB Output is correct
115 Incorrect 13 ms 5720 KB Output isn't correct
116 Halted 0 ms 0 KB -