답안 #765406

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
765406 2023-06-24T12:24:35 Z thinknoexit 꿈 (IOI13_dreaming) C++17
47 / 100
62 ms 18740 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
using ll = long long;
vector<pair<int, ll>> adj[100100];
bool vis[100100];
int big[100100];
ll dp[100100][2], 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, ll 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<ll> ans;
    for (int i = 0;i < n;i++) {
        if (vis[i]) continue;
        mn = 1e18;
        dfs(i);
        dfs2(i);
        ans.push_back(mn);
    }
    sort(ans.begin(), ans.end(), greater<int>());
    ll l = mx, r = 1e10;
    while (l < r) {
        ll mid = (l + r) / 2;
        ll nowmx = ans[0], tmx = 0;
        ll cnt = 0;
        bool ch = 1;
        for (int i = 1;i < (int)ans.size();i++) {
            cnt++;
            if (cnt * L + nowmx + ans[i] > mid) {
                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 33 ms 13788 KB Output is correct
2 Correct 32 ms 13504 KB Output is correct
3 Correct 23 ms 11512 KB Output is correct
4 Correct 6 ms 4564 KB Output is correct
5 Correct 5 ms 4060 KB Output is correct
6 Correct 10 ms 5588 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 17 ms 7764 KB Output is correct
9 Correct 25 ms 10084 KB Output is correct
10 Correct 2 ms 3156 KB Output is correct
11 Correct 30 ms 11196 KB Output is correct
12 Correct 36 ms 12680 KB Output is correct
13 Correct 2 ms 3156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3028 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 3028 KB Output is correct
8 Correct 1 ms 3028 KB Output is correct
9 Correct 3 ms 3028 KB Output is correct
10 Correct 1 ms 3028 KB Output is correct
11 Correct 2 ms 3028 KB Output is correct
12 Correct 1 ms 3028 KB Output is correct
13 Correct 2 ms 3028 KB Output is correct
14 Correct 1 ms 3028 KB Output is correct
15 Correct 1 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 1 ms 3028 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
21 Correct 1 ms 3028 KB Output is correct
22 Correct 1 ms 3028 KB Output is correct
23 Correct 1 ms 3028 KB Output is correct
24 Correct 2 ms 3028 KB Output is correct
25 Correct 1 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 13788 KB Output is correct
2 Correct 32 ms 13504 KB Output is correct
3 Correct 23 ms 11512 KB Output is correct
4 Correct 6 ms 4564 KB Output is correct
5 Correct 5 ms 4060 KB Output is correct
6 Correct 10 ms 5588 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 17 ms 7764 KB Output is correct
9 Correct 25 ms 10084 KB Output is correct
10 Correct 2 ms 3156 KB Output is correct
11 Correct 30 ms 11196 KB Output is correct
12 Correct 36 ms 12680 KB Output is correct
13 Correct 2 ms 3156 KB Output is correct
14 Correct 1 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 2 ms 3028 KB Output is correct
21 Correct 1 ms 3028 KB Output is correct
22 Correct 3 ms 3028 KB Output is correct
23 Correct 1 ms 3028 KB Output is correct
24 Correct 2 ms 3028 KB Output is correct
25 Correct 1 ms 3028 KB Output is correct
26 Correct 2 ms 3028 KB Output is correct
27 Correct 1 ms 3028 KB Output is correct
28 Correct 1 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 1 ms 3028 KB Output is correct
33 Correct 2 ms 3028 KB Output is correct
34 Correct 1 ms 3028 KB Output is correct
35 Correct 1 ms 3028 KB Output is correct
36 Correct 1 ms 3028 KB Output is correct
37 Correct 2 ms 3028 KB Output is correct
38 Correct 1 ms 3028 KB Output is correct
39 Correct 41 ms 13748 KB Output is correct
40 Correct 33 ms 13556 KB Output is correct
41 Correct 23 ms 11488 KB Output is correct
42 Correct 6 ms 4564 KB Output is correct
43 Correct 2 ms 3028 KB Output is correct
44 Correct 2 ms 3028 KB Output is correct
45 Correct 1 ms 3028 KB Output is correct
46 Correct 2 ms 3028 KB Output is correct
47 Correct 2 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 2 ms 3028 KB Output is correct
51 Correct 1 ms 3028 KB Output is correct
52 Correct 2 ms 3028 KB Output is correct
53 Correct 1 ms 3028 KB Output is correct
54 Correct 2 ms 2972 KB Output is correct
55 Correct 2 ms 3028 KB Output is correct
56 Correct 1 ms 3028 KB Output is correct
57 Correct 42 ms 11768 KB Output is correct
58 Correct 41 ms 11708 KB Output is correct
59 Correct 42 ms 11476 KB Output is correct
60 Correct 42 ms 11460 KB Output is correct
61 Correct 49 ms 11220 KB Output is correct
62 Correct 41 ms 11220 KB Output is correct
63 Correct 45 ms 11032 KB Output is correct
64 Correct 39 ms 10944 KB Output is correct
65 Correct 40 ms 10956 KB Output is correct
66 Correct 49 ms 10988 KB Output is correct
67 Correct 52 ms 11516 KB Output is correct
68 Correct 42 ms 11468 KB Output is correct
69 Correct 43 ms 11468 KB Output is correct
70 Correct 44 ms 11472 KB Output is correct
71 Correct 1 ms 3028 KB Output is correct
72 Correct 3 ms 3284 KB Output is correct
73 Correct 2 ms 3284 KB Output is correct
74 Correct 2 ms 3284 KB Output is correct
75 Correct 2 ms 3284 KB Output is correct
76 Correct 3 ms 3284 KB Output is correct
77 Correct 2 ms 3312 KB Output is correct
78 Correct 2 ms 3284 KB Output is correct
79 Correct 3 ms 3284 KB Output is correct
80 Correct 41 ms 11388 KB Output is correct
81 Correct 46 ms 11404 KB Output is correct
82 Correct 40 ms 11268 KB Output is correct
83 Correct 40 ms 11240 KB Output is correct
84 Correct 2 ms 3156 KB Output is correct
85 Correct 2 ms 3156 KB Output is correct
86 Correct 2 ms 3156 KB Output is correct
87 Correct 2 ms 3284 KB Output is correct
88 Correct 3 ms 3284 KB Output is correct
89 Correct 2 ms 3156 KB Output is correct
90 Correct 2 ms 3156 KB Output is correct
91 Correct 2 ms 3196 KB Output is correct
92 Correct 2 ms 3284 KB Output is correct
93 Correct 2 ms 3156 KB Output is correct
94 Correct 1 ms 3028 KB Output is correct
95 Correct 2 ms 3028 KB Output is correct
96 Correct 1 ms 3028 KB Output is correct
97 Correct 1 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 1 ms 3028 KB Output is correct
101 Correct 1 ms 3028 KB Output is correct
102 Correct 1 ms 3080 KB Output is correct
103 Correct 2 ms 3028 KB Output is correct
104 Correct 5 ms 4052 KB Output is correct
105 Correct 9 ms 5588 KB Output is correct
106 Correct 2 ms 3028 KB Output is correct
107 Correct 17 ms 7828 KB Output is correct
108 Correct 22 ms 10152 KB Output is correct
109 Correct 2 ms 3156 KB Output is correct
110 Correct 30 ms 11220 KB Output is correct
111 Correct 42 ms 12732 KB Output is correct
112 Correct 2 ms 3156 KB Output is correct
113 Correct 62 ms 18740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 7512 KB Output is correct
2 Correct 18 ms 7496 KB Output is correct
3 Correct 17 ms 7512 KB Output is correct
4 Correct 17 ms 7508 KB Output is correct
5 Correct 21 ms 7572 KB Output is correct
6 Correct 19 ms 8224 KB Output is correct
7 Correct 17 ms 7768 KB Output is correct
8 Correct 17 ms 7512 KB Output is correct
9 Correct 17 ms 7504 KB Output is correct
10 Correct 18 ms 7708 KB Output is correct
11 Incorrect 1 ms 3028 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3028 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 3028 KB Output is correct
8 Correct 1 ms 3028 KB Output is correct
9 Correct 3 ms 3028 KB Output is correct
10 Correct 1 ms 3028 KB Output is correct
11 Correct 2 ms 3028 KB Output is correct
12 Correct 1 ms 3028 KB Output is correct
13 Correct 2 ms 3028 KB Output is correct
14 Correct 1 ms 3028 KB Output is correct
15 Correct 1 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 1 ms 3028 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
21 Correct 1 ms 3028 KB Output is correct
22 Correct 1 ms 3028 KB Output is correct
23 Correct 1 ms 3028 KB Output is correct
24 Correct 2 ms 3028 KB Output is correct
25 Correct 1 ms 3028 KB Output is correct
26 Correct 2 ms 3028 KB Output is correct
27 Correct 2 ms 3156 KB Output is correct
28 Correct 2 ms 3284 KB Output is correct
29 Correct 2 ms 3028 KB Output is correct
30 Correct 2 ms 3156 KB Output is correct
31 Correct 2 ms 3284 KB Output is correct
32 Correct 2 ms 3028 KB Output is correct
33 Correct 2 ms 3156 KB Output is correct
34 Correct 2 ms 3292 KB Output is correct
35 Correct 1 ms 3028 KB Output is correct
36 Correct 1 ms 3028 KB Output is correct
37 Correct 1 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 1 ms 3028 KB Output isn't correct
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 13788 KB Output is correct
2 Correct 32 ms 13504 KB Output is correct
3 Correct 23 ms 11512 KB Output is correct
4 Correct 6 ms 4564 KB Output is correct
5 Correct 5 ms 4060 KB Output is correct
6 Correct 10 ms 5588 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 17 ms 7764 KB Output is correct
9 Correct 25 ms 10084 KB Output is correct
10 Correct 2 ms 3156 KB Output is correct
11 Correct 30 ms 11196 KB Output is correct
12 Correct 36 ms 12680 KB Output is correct
13 Correct 2 ms 3156 KB Output is correct
14 Correct 1 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 2 ms 3028 KB Output is correct
21 Correct 1 ms 3028 KB Output is correct
22 Correct 3 ms 3028 KB Output is correct
23 Correct 1 ms 3028 KB Output is correct
24 Correct 2 ms 3028 KB Output is correct
25 Correct 1 ms 3028 KB Output is correct
26 Correct 2 ms 3028 KB Output is correct
27 Correct 1 ms 3028 KB Output is correct
28 Correct 1 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 1 ms 3028 KB Output is correct
33 Correct 2 ms 3028 KB Output is correct
34 Correct 1 ms 3028 KB Output is correct
35 Correct 1 ms 3028 KB Output is correct
36 Correct 1 ms 3028 KB Output is correct
37 Correct 2 ms 3028 KB Output is correct
38 Correct 1 ms 3028 KB Output is correct
39 Correct 41 ms 13748 KB Output is correct
40 Correct 33 ms 13556 KB Output is correct
41 Correct 23 ms 11488 KB Output is correct
42 Correct 6 ms 4564 KB Output is correct
43 Correct 2 ms 3028 KB Output is correct
44 Correct 2 ms 3028 KB Output is correct
45 Correct 1 ms 3028 KB Output is correct
46 Correct 2 ms 3028 KB Output is correct
47 Correct 2 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 2 ms 3028 KB Output is correct
51 Correct 1 ms 3028 KB Output is correct
52 Correct 2 ms 3028 KB Output is correct
53 Correct 1 ms 3028 KB Output is correct
54 Correct 2 ms 2972 KB Output is correct
55 Correct 2 ms 3028 KB Output is correct
56 Correct 1 ms 3028 KB Output is correct
57 Correct 42 ms 11768 KB Output is correct
58 Correct 41 ms 11708 KB Output is correct
59 Correct 42 ms 11476 KB Output is correct
60 Correct 42 ms 11460 KB Output is correct
61 Correct 49 ms 11220 KB Output is correct
62 Correct 41 ms 11220 KB Output is correct
63 Correct 45 ms 11032 KB Output is correct
64 Correct 39 ms 10944 KB Output is correct
65 Correct 40 ms 10956 KB Output is correct
66 Correct 49 ms 10988 KB Output is correct
67 Correct 52 ms 11516 KB Output is correct
68 Correct 42 ms 11468 KB Output is correct
69 Correct 43 ms 11468 KB Output is correct
70 Correct 44 ms 11472 KB Output is correct
71 Correct 1 ms 3028 KB Output is correct
72 Correct 3 ms 3284 KB Output is correct
73 Correct 2 ms 3284 KB Output is correct
74 Correct 2 ms 3284 KB Output is correct
75 Correct 2 ms 3284 KB Output is correct
76 Correct 3 ms 3284 KB Output is correct
77 Correct 2 ms 3312 KB Output is correct
78 Correct 2 ms 3284 KB Output is correct
79 Correct 3 ms 3284 KB Output is correct
80 Correct 41 ms 11388 KB Output is correct
81 Correct 46 ms 11404 KB Output is correct
82 Correct 40 ms 11268 KB Output is correct
83 Correct 40 ms 11240 KB Output is correct
84 Correct 2 ms 3156 KB Output is correct
85 Correct 2 ms 3156 KB Output is correct
86 Correct 2 ms 3156 KB Output is correct
87 Correct 2 ms 3284 KB Output is correct
88 Correct 3 ms 3284 KB Output is correct
89 Correct 2 ms 3156 KB Output is correct
90 Correct 2 ms 3156 KB Output is correct
91 Correct 2 ms 3196 KB Output is correct
92 Correct 2 ms 3284 KB Output is correct
93 Correct 2 ms 3156 KB Output is correct
94 Correct 1 ms 3028 KB Output is correct
95 Correct 2 ms 3028 KB Output is correct
96 Correct 1 ms 3028 KB Output is correct
97 Correct 1 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 1 ms 3028 KB Output is correct
101 Correct 1 ms 3028 KB Output is correct
102 Correct 1 ms 3080 KB Output is correct
103 Correct 2 ms 3028 KB Output is correct
104 Correct 5 ms 4052 KB Output is correct
105 Correct 9 ms 5588 KB Output is correct
106 Correct 2 ms 3028 KB Output is correct
107 Correct 17 ms 7828 KB Output is correct
108 Correct 22 ms 10152 KB Output is correct
109 Correct 2 ms 3156 KB Output is correct
110 Correct 30 ms 11220 KB Output is correct
111 Correct 42 ms 12732 KB Output is correct
112 Correct 2 ms 3156 KB Output is correct
113 Correct 62 ms 18740 KB Output is correct
114 Correct 17 ms 7512 KB Output is correct
115 Correct 18 ms 7496 KB Output is correct
116 Correct 17 ms 7512 KB Output is correct
117 Correct 17 ms 7508 KB Output is correct
118 Correct 21 ms 7572 KB Output is correct
119 Correct 19 ms 8224 KB Output is correct
120 Correct 17 ms 7768 KB Output is correct
121 Correct 17 ms 7512 KB Output is correct
122 Correct 17 ms 7504 KB Output is correct
123 Correct 18 ms 7708 KB Output is correct
124 Incorrect 1 ms 3028 KB Output isn't correct
125 Halted 0 ms 0 KB -