답안 #765402

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
765402 2023-06-24T12:19:38 Z thinknoexit 꿈 (IOI13_dreaming) C++17
47 / 100
57 ms 17520 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
using ll = long long;
vector<pair<int, int>> adj[100100];
bool vis[100100];
int p[100100], dp[100100][2], big[100100], mn, mx = 0;
void dfs(int v, int p = -1) {
    vis[v] = 1;
    for (auto& [x, w] : adj[v]) {
        if (x == p) continue;
        dfs(x, v);
        dp[v][1] = max(dp[v][1], dp[x][0] + w);
        if (dp[v][1] > dp[v][0]) swap(dp[v][0], dp[v][1]), big[v] = x;
    }
}
void dfs2(int v, int p = -1, int prev = 0) {
    dp[v][1] = max(dp[v][1], prev);
    if (dp[v][1] > dp[v][0]) swap(dp[v][0], dp[v][1]);
    mn = min(mn, dp[v][0]);
    mx = max(mx, dp[v][0] + dp[v][1]);
    for (auto& [x, w] : adj[v]) {
        if (x == p) continue;
        if (x == big[v]) dfs2(x, v, max(prev, dp[v][1]) + w);
        else dfs2(x, v, max(prev, dp[v][0]) + w);
    }
}
int travelTime(int n, int m, int L, int a[], int b[], int c[]) {
    memset(big, -1, sizeof big);
    for (int i = 0;i < m;i++) {
        adj[a[i]].push_back({ b[i],c[i] });
        adj[b[i]].push_back({ a[i],c[i] });
    }
    vector<int> ans;
    for (int i = 0;i < n;i++) {
        if (vis[i]) continue;
        mn = 1e9;
        dfs(i);
        dfs2(i);
        ans.push_back(mn);
    }
    if (m == n - 1) {
        return mx;
    }
    sort(ans.begin(), ans.end(), greater<int>());
    int l = mx, r = 1e9;
    while (l < r) {
        int mid = (l + r) / 2;
        int nowmx = ans[0], tmx = 0;
        int cnt = 0;
        bool ch = 1;
        for (int i = 1;i < (int)ans.size();i++) {
            cnt++;
            if (cnt * L + nowmx + ans[i] > mid) {
                if (cnt == 1) {
                    ch = 0;
                    break;
                }
                cnt = 1;
                nowmx = max(nowmx, tmx);
                if (cnt * L + nowmx + ans[i] > mid) {
                    ch = 0;
                    break;
                }
            }
            tmx = max(tmx, ans[i] + cnt * L);
        }
        if (ch) r = mid;
        else l = mid + 1;
    }
    return l;
}
// int U[19], V[19], W[19];
// int main() {
//     int n, m, l;
//     cin >> n >> m >> l;
//     for (int i = 0;i < m;i++) {
//         cin >> U[i] >> V[i] >> W[i];
//     }
//     cout << travelTime(n, m, l, U, V, W);
// }
/*
12 8 2
0 8 4
8 2 2
2 7 4
5 11 3
5 1 7
1 3 1
1 9 5
10 6 3
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 12872 KB Output is correct
2 Correct 36 ms 12556 KB Output is correct
3 Correct 26 ms 11100 KB Output is correct
4 Correct 6 ms 4464 KB Output is correct
5 Correct 5 ms 3812 KB Output is correct
6 Correct 9 ms 5216 KB Output is correct
7 Correct 2 ms 3036 KB Output is correct
8 Correct 16 ms 7148 KB Output is correct
9 Correct 21 ms 9256 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 28 ms 10388 KB Output is correct
12 Correct 33 ms 11560 KB Output is correct
13 Correct 2 ms 3156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3044 KB Output is correct
3 Correct 2 ms 3052 KB Output is correct
4 Correct 2 ms 3040 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 2 ms 3028 KB Output is correct
7 Correct 2 ms 3156 KB Output is correct
8 Correct 2 ms 3028 KB Output is correct
9 Correct 2 ms 3028 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 2 ms 3044 KB Output is correct
12 Correct 2 ms 3028 KB Output is correct
13 Correct 2 ms 3028 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 2 ms 3028 KB Output is correct
16 Correct 2 ms 3028 KB Output is correct
17 Correct 2 ms 3028 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 2 ms 3028 KB Output is correct
20 Correct 3 ms 3028 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 2 ms 3028 KB Output is correct
24 Correct 2 ms 3040 KB Output is correct
25 Correct 2 ms 3040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 12872 KB Output is correct
2 Correct 36 ms 12556 KB Output is correct
3 Correct 26 ms 11100 KB Output is correct
4 Correct 6 ms 4464 KB Output is correct
5 Correct 5 ms 3812 KB Output is correct
6 Correct 9 ms 5216 KB Output is correct
7 Correct 2 ms 3036 KB Output is correct
8 Correct 16 ms 7148 KB Output is correct
9 Correct 21 ms 9256 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 28 ms 10388 KB Output is correct
12 Correct 33 ms 11560 KB Output is correct
13 Correct 2 ms 3156 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 2 ms 3044 KB Output is correct
16 Correct 2 ms 3052 KB Output is correct
17 Correct 2 ms 3040 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 2 ms 3028 KB Output is correct
20 Correct 2 ms 3156 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 2 ms 3028 KB Output is correct
24 Correct 2 ms 3044 KB Output is correct
25 Correct 2 ms 3028 KB Output is correct
26 Correct 2 ms 3028 KB Output is correct
27 Correct 2 ms 3028 KB Output is correct
28 Correct 2 ms 3028 KB Output is correct
29 Correct 2 ms 3028 KB Output is correct
30 Correct 2 ms 3028 KB Output is correct
31 Correct 2 ms 3028 KB Output is correct
32 Correct 2 ms 3028 KB Output is correct
33 Correct 3 ms 3028 KB Output is correct
34 Correct 2 ms 3028 KB Output is correct
35 Correct 2 ms 3028 KB Output is correct
36 Correct 2 ms 3028 KB Output is correct
37 Correct 2 ms 3040 KB Output is correct
38 Correct 2 ms 3040 KB Output is correct
39 Correct 46 ms 12948 KB Output is correct
40 Correct 32 ms 12592 KB Output is correct
41 Correct 32 ms 11092 KB Output is correct
42 Correct 8 ms 4520 KB Output is correct
43 Correct 2 ms 3028 KB Output is correct
44 Correct 2 ms 3028 KB Output is correct
45 Correct 2 ms 3028 KB Output is correct
46 Correct 2 ms 3044 KB Output is correct
47 Correct 1 ms 3028 KB Output is correct
48 Correct 2 ms 3028 KB Output is correct
49 Correct 1 ms 3028 KB Output is correct
50 Correct 3 ms 3028 KB Output is correct
51 Correct 2 ms 3028 KB Output is correct
52 Correct 2 ms 3028 KB Output is correct
53 Correct 2 ms 3044 KB Output is correct
54 Correct 2 ms 3028 KB Output is correct
55 Correct 2 ms 3028 KB Output is correct
56 Correct 2 ms 3048 KB Output is correct
57 Correct 52 ms 10404 KB Output is correct
58 Correct 37 ms 10324 KB Output is correct
59 Correct 41 ms 10332 KB Output is correct
60 Correct 57 ms 10344 KB Output is correct
61 Correct 52 ms 10364 KB Output is correct
62 Correct 37 ms 10396 KB Output is correct
63 Correct 40 ms 10088 KB Output is correct
64 Correct 37 ms 10048 KB Output is correct
65 Correct 39 ms 10292 KB Output is correct
66 Correct 53 ms 10388 KB Output is correct
67 Correct 40 ms 10336 KB Output is correct
68 Correct 56 ms 10344 KB Output is correct
69 Correct 41 ms 10560 KB Output is correct
70 Correct 39 ms 10572 KB Output is correct
71 Correct 2 ms 3028 KB Output is correct
72 Correct 4 ms 3228 KB Output is correct
73 Correct 4 ms 3280 KB Output is correct
74 Correct 2 ms 3284 KB Output is correct
75 Correct 2 ms 3184 KB Output is correct
76 Correct 3 ms 3284 KB Output is correct
77 Correct 3 ms 3284 KB Output is correct
78 Correct 3 ms 3284 KB Output is correct
79 Correct 2 ms 3284 KB Output is correct
80 Correct 37 ms 10332 KB Output is correct
81 Correct 37 ms 10316 KB Output is correct
82 Correct 38 ms 10360 KB Output is correct
83 Correct 38 ms 10384 KB Output is correct
84 Correct 2 ms 3180 KB Output is correct
85 Correct 3 ms 3156 KB Output is correct
86 Correct 2 ms 3156 KB Output is correct
87 Correct 3 ms 3244 KB Output is correct
88 Correct 3 ms 3156 KB Output is correct
89 Correct 3 ms 3212 KB Output is correct
90 Correct 3 ms 3220 KB Output is correct
91 Correct 3 ms 3156 KB Output is correct
92 Correct 3 ms 3180 KB Output is correct
93 Correct 3 ms 3156 KB Output is correct
94 Correct 2 ms 3040 KB Output is correct
95 Correct 2 ms 3028 KB Output is correct
96 Correct 2 ms 3028 KB Output is correct
97 Correct 2 ms 3028 KB Output is correct
98 Correct 2 ms 3028 KB Output is correct
99 Correct 1 ms 3028 KB Output is correct
100 Correct 3 ms 3040 KB Output is correct
101 Correct 2 ms 3028 KB Output is correct
102 Correct 2 ms 3028 KB Output is correct
103 Correct 2 ms 3028 KB Output is correct
104 Correct 5 ms 3924 KB Output is correct
105 Correct 9 ms 5204 KB Output is correct
106 Correct 2 ms 3028 KB Output is correct
107 Correct 20 ms 7156 KB Output is correct
108 Correct 26 ms 9316 KB Output is correct
109 Correct 2 ms 3028 KB Output is correct
110 Correct 31 ms 10380 KB Output is correct
111 Correct 42 ms 11552 KB Output is correct
112 Correct 2 ms 3156 KB Output is correct
113 Correct 44 ms 17520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 7000 KB Output is correct
2 Correct 17 ms 7040 KB Output is correct
3 Correct 17 ms 7000 KB Output is correct
4 Correct 17 ms 6960 KB Output is correct
5 Correct 16 ms 6988 KB Output is correct
6 Correct 25 ms 7384 KB Output is correct
7 Correct 16 ms 7128 KB Output is correct
8 Correct 16 ms 6896 KB Output is correct
9 Correct 19 ms 6872 KB Output is correct
10 Correct 22 ms 7052 KB Output is correct
11 Incorrect 2 ms 3044 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3044 KB Output is correct
3 Correct 2 ms 3052 KB Output is correct
4 Correct 2 ms 3040 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 2 ms 3028 KB Output is correct
7 Correct 2 ms 3156 KB Output is correct
8 Correct 2 ms 3028 KB Output is correct
9 Correct 2 ms 3028 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 2 ms 3044 KB Output is correct
12 Correct 2 ms 3028 KB Output is correct
13 Correct 2 ms 3028 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 2 ms 3028 KB Output is correct
16 Correct 2 ms 3028 KB Output is correct
17 Correct 2 ms 3028 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 2 ms 3028 KB Output is correct
20 Correct 3 ms 3028 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 2 ms 3028 KB Output is correct
24 Correct 2 ms 3040 KB Output is correct
25 Correct 2 ms 3040 KB Output is correct
26 Correct 3 ms 3052 KB Output is correct
27 Correct 2 ms 3156 KB Output is correct
28 Correct 2 ms 3156 KB Output is correct
29 Correct 2 ms 3052 KB Output is correct
30 Correct 2 ms 3184 KB Output is correct
31 Correct 2 ms 3156 KB Output is correct
32 Correct 2 ms 3028 KB Output is correct
33 Correct 2 ms 3156 KB Output is correct
34 Correct 3 ms 3156 KB Output is correct
35 Correct 2 ms 3028 KB Output is correct
36 Correct 2 ms 3048 KB Output is correct
37 Correct 2 ms 3028 KB Output is correct
38 Correct 2 ms 3028 KB Output is correct
39 Correct 2 ms 3028 KB Output is correct
40 Incorrect 2 ms 3028 KB Output isn't correct
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 12872 KB Output is correct
2 Correct 36 ms 12556 KB Output is correct
3 Correct 26 ms 11100 KB Output is correct
4 Correct 6 ms 4464 KB Output is correct
5 Correct 5 ms 3812 KB Output is correct
6 Correct 9 ms 5216 KB Output is correct
7 Correct 2 ms 3036 KB Output is correct
8 Correct 16 ms 7148 KB Output is correct
9 Correct 21 ms 9256 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 28 ms 10388 KB Output is correct
12 Correct 33 ms 11560 KB Output is correct
13 Correct 2 ms 3156 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 2 ms 3044 KB Output is correct
16 Correct 2 ms 3052 KB Output is correct
17 Correct 2 ms 3040 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 2 ms 3028 KB Output is correct
20 Correct 2 ms 3156 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 2 ms 3028 KB Output is correct
24 Correct 2 ms 3044 KB Output is correct
25 Correct 2 ms 3028 KB Output is correct
26 Correct 2 ms 3028 KB Output is correct
27 Correct 2 ms 3028 KB Output is correct
28 Correct 2 ms 3028 KB Output is correct
29 Correct 2 ms 3028 KB Output is correct
30 Correct 2 ms 3028 KB Output is correct
31 Correct 2 ms 3028 KB Output is correct
32 Correct 2 ms 3028 KB Output is correct
33 Correct 3 ms 3028 KB Output is correct
34 Correct 2 ms 3028 KB Output is correct
35 Correct 2 ms 3028 KB Output is correct
36 Correct 2 ms 3028 KB Output is correct
37 Correct 2 ms 3040 KB Output is correct
38 Correct 2 ms 3040 KB Output is correct
39 Correct 46 ms 12948 KB Output is correct
40 Correct 32 ms 12592 KB Output is correct
41 Correct 32 ms 11092 KB Output is correct
42 Correct 8 ms 4520 KB Output is correct
43 Correct 2 ms 3028 KB Output is correct
44 Correct 2 ms 3028 KB Output is correct
45 Correct 2 ms 3028 KB Output is correct
46 Correct 2 ms 3044 KB Output is correct
47 Correct 1 ms 3028 KB Output is correct
48 Correct 2 ms 3028 KB Output is correct
49 Correct 1 ms 3028 KB Output is correct
50 Correct 3 ms 3028 KB Output is correct
51 Correct 2 ms 3028 KB Output is correct
52 Correct 2 ms 3028 KB Output is correct
53 Correct 2 ms 3044 KB Output is correct
54 Correct 2 ms 3028 KB Output is correct
55 Correct 2 ms 3028 KB Output is correct
56 Correct 2 ms 3048 KB Output is correct
57 Correct 52 ms 10404 KB Output is correct
58 Correct 37 ms 10324 KB Output is correct
59 Correct 41 ms 10332 KB Output is correct
60 Correct 57 ms 10344 KB Output is correct
61 Correct 52 ms 10364 KB Output is correct
62 Correct 37 ms 10396 KB Output is correct
63 Correct 40 ms 10088 KB Output is correct
64 Correct 37 ms 10048 KB Output is correct
65 Correct 39 ms 10292 KB Output is correct
66 Correct 53 ms 10388 KB Output is correct
67 Correct 40 ms 10336 KB Output is correct
68 Correct 56 ms 10344 KB Output is correct
69 Correct 41 ms 10560 KB Output is correct
70 Correct 39 ms 10572 KB Output is correct
71 Correct 2 ms 3028 KB Output is correct
72 Correct 4 ms 3228 KB Output is correct
73 Correct 4 ms 3280 KB Output is correct
74 Correct 2 ms 3284 KB Output is correct
75 Correct 2 ms 3184 KB Output is correct
76 Correct 3 ms 3284 KB Output is correct
77 Correct 3 ms 3284 KB Output is correct
78 Correct 3 ms 3284 KB Output is correct
79 Correct 2 ms 3284 KB Output is correct
80 Correct 37 ms 10332 KB Output is correct
81 Correct 37 ms 10316 KB Output is correct
82 Correct 38 ms 10360 KB Output is correct
83 Correct 38 ms 10384 KB Output is correct
84 Correct 2 ms 3180 KB Output is correct
85 Correct 3 ms 3156 KB Output is correct
86 Correct 2 ms 3156 KB Output is correct
87 Correct 3 ms 3244 KB Output is correct
88 Correct 3 ms 3156 KB Output is correct
89 Correct 3 ms 3212 KB Output is correct
90 Correct 3 ms 3220 KB Output is correct
91 Correct 3 ms 3156 KB Output is correct
92 Correct 3 ms 3180 KB Output is correct
93 Correct 3 ms 3156 KB Output is correct
94 Correct 2 ms 3040 KB Output is correct
95 Correct 2 ms 3028 KB Output is correct
96 Correct 2 ms 3028 KB Output is correct
97 Correct 2 ms 3028 KB Output is correct
98 Correct 2 ms 3028 KB Output is correct
99 Correct 1 ms 3028 KB Output is correct
100 Correct 3 ms 3040 KB Output is correct
101 Correct 2 ms 3028 KB Output is correct
102 Correct 2 ms 3028 KB Output is correct
103 Correct 2 ms 3028 KB Output is correct
104 Correct 5 ms 3924 KB Output is correct
105 Correct 9 ms 5204 KB Output is correct
106 Correct 2 ms 3028 KB Output is correct
107 Correct 20 ms 7156 KB Output is correct
108 Correct 26 ms 9316 KB Output is correct
109 Correct 2 ms 3028 KB Output is correct
110 Correct 31 ms 10380 KB Output is correct
111 Correct 42 ms 11552 KB Output is correct
112 Correct 2 ms 3156 KB Output is correct
113 Correct 44 ms 17520 KB Output is correct
114 Correct 16 ms 7000 KB Output is correct
115 Correct 17 ms 7040 KB Output is correct
116 Correct 17 ms 7000 KB Output is correct
117 Correct 17 ms 6960 KB Output is correct
118 Correct 16 ms 6988 KB Output is correct
119 Correct 25 ms 7384 KB Output is correct
120 Correct 16 ms 7128 KB Output is correct
121 Correct 16 ms 6896 KB Output is correct
122 Correct 19 ms 6872 KB Output is correct
123 Correct 22 ms 7052 KB Output is correct
124 Incorrect 2 ms 3044 KB Output isn't correct
125 Halted 0 ms 0 KB -