Submission #1025920

# Submission time Handle Problem Language Result Execution time Memory
1025920 2024-07-17T11:14:12 Z onbert Dreaming (IOI13_dreaming) C++17
47 / 100
67 ms 14124 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 = l;
    if (vals.size() == 1) ans1 += vals[0];
    else if (vals.size() >= 2) ans1 += 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 36 ms 13020 KB Output is correct
2 Correct 35 ms 13032 KB Output is correct
3 Correct 26 ms 9672 KB Output is correct
4 Correct 6 ms 4184 KB Output is correct
5 Correct 5 ms 3676 KB Output is correct
6 Correct 11 ms 5276 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 21 ms 6444 KB Output is correct
9 Correct 26 ms 7888 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 36 ms 9520 KB Output is correct
12 Correct 41 ms 11476 KB Output is correct
13 Correct 2 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2804 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 2 ms 2648 KB Output is correct
13 Correct 1 ms 2648 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2796 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 13020 KB Output is correct
2 Correct 35 ms 13032 KB Output is correct
3 Correct 26 ms 9672 KB Output is correct
4 Correct 6 ms 4184 KB Output is correct
5 Correct 5 ms 3676 KB Output is correct
6 Correct 11 ms 5276 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 21 ms 6444 KB Output is correct
9 Correct 26 ms 7888 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 36 ms 9520 KB Output is correct
12 Correct 41 ms 11476 KB Output is correct
13 Correct 2 ms 2648 KB Output is correct
14 Correct 2 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2804 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2648 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2648 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2796 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 2 ms 2652 KB Output is correct
39 Correct 38 ms 13012 KB Output is correct
40 Correct 34 ms 13004 KB Output is correct
41 Correct 24 ms 9684 KB Output is correct
42 Correct 6 ms 4272 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 2 ms 2652 KB Output is correct
47 Correct 1 ms 2792 KB Output is correct
48 Correct 3 ms 2652 KB Output is correct
49 Correct 2 ms 2652 KB Output is correct
50 Correct 1 ms 2652 KB Output is correct
51 Correct 2 ms 2648 KB Output is correct
52 Correct 2 ms 2652 KB Output is correct
53 Correct 2 ms 2612 KB Output is correct
54 Correct 2 ms 2652 KB Output is correct
55 Correct 1 ms 2652 KB Output is correct
56 Correct 2 ms 2648 KB Output is correct
57 Correct 56 ms 9920 KB Output is correct
58 Correct 66 ms 9680 KB Output is correct
59 Correct 58 ms 9740 KB Output is correct
60 Correct 43 ms 9556 KB Output is correct
61 Correct 46 ms 9680 KB Output is correct
62 Correct 47 ms 9552 KB Output is correct
63 Correct 67 ms 9684 KB Output is correct
64 Correct 39 ms 9684 KB Output is correct
65 Correct 39 ms 9688 KB Output is correct
66 Correct 43 ms 9684 KB Output is correct
67 Correct 43 ms 9676 KB Output is correct
68 Correct 45 ms 9812 KB Output is correct
69 Correct 42 ms 9552 KB Output is correct
70 Correct 49 ms 9608 KB Output is correct
71 Correct 1 ms 2648 KB Output is correct
72 Correct 2 ms 2904 KB Output is correct
73 Correct 2 ms 2908 KB Output is correct
74 Correct 2 ms 2908 KB Output is correct
75 Correct 2 ms 2844 KB Output is correct
76 Correct 2 ms 2808 KB Output is correct
77 Correct 2 ms 2908 KB Output is correct
78 Correct 2 ms 2908 KB Output is correct
79 Correct 2 ms 2856 KB Output is correct
80 Correct 47 ms 9652 KB Output is correct
81 Correct 43 ms 9676 KB Output is correct
82 Correct 40 ms 9584 KB Output is correct
83 Correct 40 ms 9676 KB Output is correct
84 Correct 3 ms 2908 KB Output is correct
85 Correct 2 ms 2908 KB Output is correct
86 Correct 2 ms 2808 KB Output is correct
87 Correct 2 ms 2836 KB Output is correct
88 Correct 2 ms 2908 KB Output is correct
89 Correct 2 ms 2908 KB Output is correct
90 Correct 2 ms 2908 KB Output is correct
91 Correct 2 ms 2908 KB Output is correct
92 Correct 3 ms 2908 KB Output is correct
93 Correct 2 ms 2908 KB Output is correct
94 Correct 2 ms 2652 KB Output is correct
95 Correct 1 ms 2652 KB Output is correct
96 Correct 1 ms 2652 KB Output is correct
97 Correct 1 ms 2652 KB Output is correct
98 Correct 1 ms 2652 KB Output is correct
99 Correct 1 ms 2652 KB Output is correct
100 Correct 2 ms 2792 KB Output is correct
101 Correct 1 ms 2804 KB Output is correct
102 Correct 1 ms 2652 KB Output is correct
103 Correct 1 ms 2652 KB Output is correct
104 Correct 5 ms 3676 KB Output is correct
105 Correct 10 ms 5212 KB Output is correct
106 Correct 1 ms 2724 KB Output is correct
107 Correct 18 ms 6488 KB Output is correct
108 Correct 23 ms 7892 KB Output is correct
109 Correct 2 ms 2652 KB Output is correct
110 Correct 33 ms 9520 KB Output is correct
111 Correct 39 ms 11480 KB Output is correct
112 Correct 2 ms 2908 KB Output is correct
113 Correct 52 ms 14124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 6232 KB Output is correct
2 Incorrect 22 ms 6236 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2804 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 2 ms 2648 KB Output is correct
13 Correct 1 ms 2648 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2796 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 3 ms 2648 KB Output is correct
27 Correct 4 ms 2808 KB Output is correct
28 Correct 2 ms 2812 KB Output is correct
29 Correct 2 ms 2652 KB Output is correct
30 Correct 2 ms 2908 KB Output is correct
31 Correct 2 ms 2904 KB Output is correct
32 Incorrect 2 ms 2652 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 13020 KB Output is correct
2 Correct 35 ms 13032 KB Output is correct
3 Correct 26 ms 9672 KB Output is correct
4 Correct 6 ms 4184 KB Output is correct
5 Correct 5 ms 3676 KB Output is correct
6 Correct 11 ms 5276 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 21 ms 6444 KB Output is correct
9 Correct 26 ms 7888 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 36 ms 9520 KB Output is correct
12 Correct 41 ms 11476 KB Output is correct
13 Correct 2 ms 2648 KB Output is correct
14 Correct 2 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2804 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2648 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2648 KB Output is correct
33 Correct 2 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2796 KB Output is correct
36 Correct 2 ms 2652 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 2 ms 2652 KB Output is correct
39 Correct 38 ms 13012 KB Output is correct
40 Correct 34 ms 13004 KB Output is correct
41 Correct 24 ms 9684 KB Output is correct
42 Correct 6 ms 4272 KB Output is correct
43 Correct 2 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 2 ms 2652 KB Output is correct
47 Correct 1 ms 2792 KB Output is correct
48 Correct 3 ms 2652 KB Output is correct
49 Correct 2 ms 2652 KB Output is correct
50 Correct 1 ms 2652 KB Output is correct
51 Correct 2 ms 2648 KB Output is correct
52 Correct 2 ms 2652 KB Output is correct
53 Correct 2 ms 2612 KB Output is correct
54 Correct 2 ms 2652 KB Output is correct
55 Correct 1 ms 2652 KB Output is correct
56 Correct 2 ms 2648 KB Output is correct
57 Correct 56 ms 9920 KB Output is correct
58 Correct 66 ms 9680 KB Output is correct
59 Correct 58 ms 9740 KB Output is correct
60 Correct 43 ms 9556 KB Output is correct
61 Correct 46 ms 9680 KB Output is correct
62 Correct 47 ms 9552 KB Output is correct
63 Correct 67 ms 9684 KB Output is correct
64 Correct 39 ms 9684 KB Output is correct
65 Correct 39 ms 9688 KB Output is correct
66 Correct 43 ms 9684 KB Output is correct
67 Correct 43 ms 9676 KB Output is correct
68 Correct 45 ms 9812 KB Output is correct
69 Correct 42 ms 9552 KB Output is correct
70 Correct 49 ms 9608 KB Output is correct
71 Correct 1 ms 2648 KB Output is correct
72 Correct 2 ms 2904 KB Output is correct
73 Correct 2 ms 2908 KB Output is correct
74 Correct 2 ms 2908 KB Output is correct
75 Correct 2 ms 2844 KB Output is correct
76 Correct 2 ms 2808 KB Output is correct
77 Correct 2 ms 2908 KB Output is correct
78 Correct 2 ms 2908 KB Output is correct
79 Correct 2 ms 2856 KB Output is correct
80 Correct 47 ms 9652 KB Output is correct
81 Correct 43 ms 9676 KB Output is correct
82 Correct 40 ms 9584 KB Output is correct
83 Correct 40 ms 9676 KB Output is correct
84 Correct 3 ms 2908 KB Output is correct
85 Correct 2 ms 2908 KB Output is correct
86 Correct 2 ms 2808 KB Output is correct
87 Correct 2 ms 2836 KB Output is correct
88 Correct 2 ms 2908 KB Output is correct
89 Correct 2 ms 2908 KB Output is correct
90 Correct 2 ms 2908 KB Output is correct
91 Correct 2 ms 2908 KB Output is correct
92 Correct 3 ms 2908 KB Output is correct
93 Correct 2 ms 2908 KB Output is correct
94 Correct 2 ms 2652 KB Output is correct
95 Correct 1 ms 2652 KB Output is correct
96 Correct 1 ms 2652 KB Output is correct
97 Correct 1 ms 2652 KB Output is correct
98 Correct 1 ms 2652 KB Output is correct
99 Correct 1 ms 2652 KB Output is correct
100 Correct 2 ms 2792 KB Output is correct
101 Correct 1 ms 2804 KB Output is correct
102 Correct 1 ms 2652 KB Output is correct
103 Correct 1 ms 2652 KB Output is correct
104 Correct 5 ms 3676 KB Output is correct
105 Correct 10 ms 5212 KB Output is correct
106 Correct 1 ms 2724 KB Output is correct
107 Correct 18 ms 6488 KB Output is correct
108 Correct 23 ms 7892 KB Output is correct
109 Correct 2 ms 2652 KB Output is correct
110 Correct 33 ms 9520 KB Output is correct
111 Correct 39 ms 11480 KB Output is correct
112 Correct 2 ms 2908 KB Output is correct
113 Correct 52 ms 14124 KB Output is correct
114 Correct 18 ms 6232 KB Output is correct
115 Incorrect 22 ms 6236 KB Output isn't correct
116 Halted 0 ms 0 KB -