답안 #1025917

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025917 2024-07-17T11:12:17 Z onbert 꿈 (IOI13_dreaming) C++17
47 / 100
55 ms 14796 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 ans1 = l, ans2 = 0;
    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);
        ans1 += cost;
    }
    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;
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 12252 KB Output is correct
2 Correct 33 ms 12236 KB Output is correct
3 Correct 22 ms 8908 KB Output is correct
4 Correct 9 ms 4184 KB Output is correct
5 Correct 5 ms 3420 KB Output is correct
6 Correct 10 ms 4876 KB Output is correct
7 Correct 2 ms 2804 KB Output is correct
8 Correct 18 ms 5980 KB Output is correct
9 Correct 24 ms 7388 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 32 ms 8844 KB Output is correct
12 Correct 44 ms 10756 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 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 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2796 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 2 ms 2908 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 12252 KB Output is correct
2 Correct 33 ms 12236 KB Output is correct
3 Correct 22 ms 8908 KB Output is correct
4 Correct 9 ms 4184 KB Output is correct
5 Correct 5 ms 3420 KB Output is correct
6 Correct 10 ms 4876 KB Output is correct
7 Correct 2 ms 2804 KB Output is correct
8 Correct 18 ms 5980 KB Output is correct
9 Correct 24 ms 7388 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 32 ms 8844 KB Output is correct
12 Correct 44 ms 10756 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 2 ms 2648 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 1 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2796 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 2 ms 2908 KB Output is correct
28 Correct 1 ms 2648 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2648 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2800 KB Output is correct
39 Correct 35 ms 13528 KB Output is correct
40 Correct 33 ms 13528 KB Output is correct
41 Correct 26 ms 9908 KB Output is correct
42 Correct 6 ms 4184 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 1 ms 2652 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 1 ms 2652 KB Output is correct
49 Correct 1 ms 2652 KB Output is correct
50 Correct 1 ms 2652 KB Output is correct
51 Correct 1 ms 2652 KB Output is correct
52 Correct 1 ms 2648 KB Output is correct
53 Correct 1 ms 2652 KB Output is correct
54 Correct 1 ms 2652 KB Output is correct
55 Correct 1 ms 2796 KB Output is correct
56 Correct 1 ms 2652 KB Output is correct
57 Correct 46 ms 10296 KB Output is correct
58 Correct 53 ms 10048 KB Output is correct
59 Correct 44 ms 10192 KB Output is correct
60 Correct 43 ms 9808 KB Output is correct
61 Correct 43 ms 10196 KB Output is correct
62 Correct 39 ms 9976 KB Output is correct
63 Correct 38 ms 9944 KB Output is correct
64 Correct 40 ms 10012 KB Output is correct
65 Correct 39 ms 10052 KB Output is correct
66 Correct 38 ms 10036 KB Output is correct
67 Correct 45 ms 10192 KB Output is correct
68 Correct 43 ms 10080 KB Output is correct
69 Correct 47 ms 10196 KB Output is correct
70 Correct 55 ms 10188 KB Output is correct
71 Correct 2 ms 2652 KB Output is correct
72 Correct 2 ms 2908 KB Output is correct
73 Correct 2 ms 2836 KB Output is correct
74 Correct 3 ms 2904 KB Output is correct
75 Correct 2 ms 2904 KB Output is correct
76 Correct 2 ms 2908 KB Output is correct
77 Correct 2 ms 2800 KB Output is correct
78 Correct 3 ms 2908 KB Output is correct
79 Correct 3 ms 2904 KB Output is correct
80 Correct 50 ms 10084 KB Output is correct
81 Correct 49 ms 10116 KB Output is correct
82 Correct 40 ms 10312 KB Output is correct
83 Correct 39 ms 10188 KB Output is correct
84 Correct 2 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 2 ms 4212 KB Output is correct
93 Correct 3 ms 4188 KB Output is correct
94 Correct 2 ms 3932 KB Output is correct
95 Correct 1 ms 3932 KB Output is correct
96 Correct 1 ms 3932 KB Output is correct
97 Correct 1 ms 3928 KB Output is correct
98 Correct 1 ms 3932 KB Output is correct
99 Correct 1 ms 3932 KB Output is correct
100 Correct 1 ms 3932 KB Output is correct
101 Correct 1 ms 3932 KB Output is correct
102 Correct 1 ms 3932 KB Output is correct
103 Correct 1 ms 3932 KB Output is correct
104 Correct 5 ms 4956 KB Output is correct
105 Correct 10 ms 6236 KB Output is correct
106 Correct 1 ms 4188 KB Output is correct
107 Correct 16 ms 7548 KB Output is correct
108 Correct 29 ms 8980 KB Output is correct
109 Correct 2 ms 4184 KB Output is correct
110 Correct 32 ms 10448 KB Output is correct
111 Correct 38 ms 11980 KB Output is correct
112 Correct 1 ms 4184 KB Output is correct
113 Correct 53 ms 14796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 6232 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 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 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2796 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 2 ms 2908 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2800 KB Output is correct
26 Correct 2 ms 4188 KB Output is correct
27 Correct 2 ms 4188 KB Output is correct
28 Correct 2 ms 4188 KB Output is correct
29 Incorrect 1 ms 4188 KB Output isn't correct
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 12252 KB Output is correct
2 Correct 33 ms 12236 KB Output is correct
3 Correct 22 ms 8908 KB Output is correct
4 Correct 9 ms 4184 KB Output is correct
5 Correct 5 ms 3420 KB Output is correct
6 Correct 10 ms 4876 KB Output is correct
7 Correct 2 ms 2804 KB Output is correct
8 Correct 18 ms 5980 KB Output is correct
9 Correct 24 ms 7388 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 32 ms 8844 KB Output is correct
12 Correct 44 ms 10756 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 2 ms 2648 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 1 ms 2652 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2796 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 2 ms 2908 KB Output is correct
28 Correct 1 ms 2648 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2648 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 2 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2800 KB Output is correct
39 Correct 35 ms 13528 KB Output is correct
40 Correct 33 ms 13528 KB Output is correct
41 Correct 26 ms 9908 KB Output is correct
42 Correct 6 ms 4184 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 1 ms 2652 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 1 ms 2652 KB Output is correct
49 Correct 1 ms 2652 KB Output is correct
50 Correct 1 ms 2652 KB Output is correct
51 Correct 1 ms 2652 KB Output is correct
52 Correct 1 ms 2648 KB Output is correct
53 Correct 1 ms 2652 KB Output is correct
54 Correct 1 ms 2652 KB Output is correct
55 Correct 1 ms 2796 KB Output is correct
56 Correct 1 ms 2652 KB Output is correct
57 Correct 46 ms 10296 KB Output is correct
58 Correct 53 ms 10048 KB Output is correct
59 Correct 44 ms 10192 KB Output is correct
60 Correct 43 ms 9808 KB Output is correct
61 Correct 43 ms 10196 KB Output is correct
62 Correct 39 ms 9976 KB Output is correct
63 Correct 38 ms 9944 KB Output is correct
64 Correct 40 ms 10012 KB Output is correct
65 Correct 39 ms 10052 KB Output is correct
66 Correct 38 ms 10036 KB Output is correct
67 Correct 45 ms 10192 KB Output is correct
68 Correct 43 ms 10080 KB Output is correct
69 Correct 47 ms 10196 KB Output is correct
70 Correct 55 ms 10188 KB Output is correct
71 Correct 2 ms 2652 KB Output is correct
72 Correct 2 ms 2908 KB Output is correct
73 Correct 2 ms 2836 KB Output is correct
74 Correct 3 ms 2904 KB Output is correct
75 Correct 2 ms 2904 KB Output is correct
76 Correct 2 ms 2908 KB Output is correct
77 Correct 2 ms 2800 KB Output is correct
78 Correct 3 ms 2908 KB Output is correct
79 Correct 3 ms 2904 KB Output is correct
80 Correct 50 ms 10084 KB Output is correct
81 Correct 49 ms 10116 KB Output is correct
82 Correct 40 ms 10312 KB Output is correct
83 Correct 39 ms 10188 KB Output is correct
84 Correct 2 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 2 ms 4212 KB Output is correct
93 Correct 3 ms 4188 KB Output is correct
94 Correct 2 ms 3932 KB Output is correct
95 Correct 1 ms 3932 KB Output is correct
96 Correct 1 ms 3932 KB Output is correct
97 Correct 1 ms 3928 KB Output is correct
98 Correct 1 ms 3932 KB Output is correct
99 Correct 1 ms 3932 KB Output is correct
100 Correct 1 ms 3932 KB Output is correct
101 Correct 1 ms 3932 KB Output is correct
102 Correct 1 ms 3932 KB Output is correct
103 Correct 1 ms 3932 KB Output is correct
104 Correct 5 ms 4956 KB Output is correct
105 Correct 10 ms 6236 KB Output is correct
106 Correct 1 ms 4188 KB Output is correct
107 Correct 16 ms 7548 KB Output is correct
108 Correct 29 ms 8980 KB Output is correct
109 Correct 2 ms 4184 KB Output is correct
110 Correct 32 ms 10448 KB Output is correct
111 Correct 38 ms 11980 KB Output is correct
112 Correct 1 ms 4184 KB Output is correct
113 Correct 53 ms 14796 KB Output is correct
114 Incorrect 14 ms 6232 KB Output isn't correct
115 Halted 0 ms 0 KB -