답안 #369394

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
369394 2021-02-21T14:23:01 Z Falcon 자매 도시 (APIO20_swap) C++17
100 / 100
370 ms 12780 KB
#include "swap.h"

#include <bits/stdc++.h>

using namespace std;

constexpr int INF{1 << 30};

vector<int> p, p_w, sz, l_w;

int find(int i, int w) {
    while(p_w[i] <= w) i = p[i];
    return i;
}

void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
    
    p = vector<int>(N), iota(p.begin(), p.end(), 0);
    p_w = vector<int>(N, INF); 
    sz = vector<int>(N, 1), l_w = vector<int>(N, INF);

    vector<int> ord(M); iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int i, int j) { return tie(W[i], i) < tie(W[j], j); });

    vector<int> d(N);
    for(int i : ord) {
        int u = find(U[i], W[i]), v = find(V[i], W[i]);
        ++d[U[i]], ++d[V[i]];

        if(u == v) {
            l_w[u] = min(W[i], l_w[u]);
            continue;
        }

        if(sz[v] < sz[u])
            swap(u, v);

        p[u] = v;
        sz[v] += sz[u];
        p_w[u] = W[i];

        if(l_w[v] <= W[i])
            continue;
        else if(l_w[u] <= W[i])
            l_w[v] = W[i];
        else if(d[U[i]] > 2 || d[V[i]] > 2)
            l_w[v] = W[i];
        
    }
}

int getMinimumFuelCapacity(int x, int y) {
    auto check = [&](int w) {
        int u = find(x, w), v = find(y, w);
        return u == v && l_w[u] <= w;
    };

    if(!check(INF - 1))
        return -1;
    
    int w{0};
    for(int t{INF >> 1}; t > 0; t >>= 1)
        if(!check(w + t))
            w += t;

    return w + 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 43 ms 5612 KB Output is correct
10 Correct 54 ms 6836 KB Output is correct
11 Correct 54 ms 6764 KB Output is correct
12 Correct 55 ms 7148 KB Output is correct
13 Correct 56 ms 7148 KB Output is correct
14 Correct 51 ms 5996 KB Output is correct
15 Correct 138 ms 10092 KB Output is correct
16 Correct 133 ms 10060 KB Output is correct
17 Correct 142 ms 10436 KB Output is correct
18 Correct 125 ms 10348 KB Output is correct
19 Correct 157 ms 6508 KB Output is correct
20 Correct 275 ms 10728 KB Output is correct
21 Correct 296 ms 10956 KB Output is correct
22 Correct 301 ms 11204 KB Output is correct
23 Correct 166 ms 11332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 163 ms 10788 KB Output is correct
4 Correct 162 ms 10816 KB Output is correct
5 Correct 171 ms 11024 KB Output is correct
6 Correct 162 ms 10820 KB Output is correct
7 Correct 165 ms 10984 KB Output is correct
8 Correct 162 ms 10808 KB Output is correct
9 Correct 169 ms 10808 KB Output is correct
10 Correct 165 ms 10956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 43 ms 5612 KB Output is correct
11 Correct 54 ms 6836 KB Output is correct
12 Correct 54 ms 6764 KB Output is correct
13 Correct 55 ms 7148 KB Output is correct
14 Correct 56 ms 7148 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 2 ms 364 KB Output is correct
34 Correct 7 ms 1260 KB Output is correct
35 Correct 52 ms 6892 KB Output is correct
36 Correct 53 ms 6892 KB Output is correct
37 Correct 52 ms 6784 KB Output is correct
38 Correct 52 ms 6764 KB Output is correct
39 Correct 51 ms 6764 KB Output is correct
40 Correct 47 ms 6124 KB Output is correct
41 Correct 57 ms 7200 KB Output is correct
42 Correct 53 ms 6892 KB Output is correct
43 Correct 51 ms 6892 KB Output is correct
44 Correct 56 ms 7148 KB Output is correct
45 Correct 86 ms 8996 KB Output is correct
46 Correct 52 ms 6912 KB Output is correct
47 Correct 52 ms 6892 KB Output is correct
48 Correct 58 ms 7404 KB Output is correct
49 Correct 85 ms 7404 KB Output is correct
50 Correct 65 ms 6124 KB Output is correct
51 Correct 74 ms 7788 KB Output is correct
52 Correct 93 ms 10092 KB Output is correct
53 Correct 102 ms 10860 KB Output is correct
54 Correct 120 ms 11500 KB Output is correct
55 Correct 53 ms 6932 KB Output is correct
56 Correct 101 ms 10624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 43 ms 5612 KB Output is correct
10 Correct 54 ms 6836 KB Output is correct
11 Correct 54 ms 6764 KB Output is correct
12 Correct 55 ms 7148 KB Output is correct
13 Correct 56 ms 7148 KB Output is correct
14 Correct 51 ms 5996 KB Output is correct
15 Correct 138 ms 10092 KB Output is correct
16 Correct 133 ms 10060 KB Output is correct
17 Correct 142 ms 10436 KB Output is correct
18 Correct 125 ms 10348 KB Output is correct
19 Correct 163 ms 10788 KB Output is correct
20 Correct 162 ms 10816 KB Output is correct
21 Correct 171 ms 11024 KB Output is correct
22 Correct 162 ms 10820 KB Output is correct
23 Correct 165 ms 10984 KB Output is correct
24 Correct 162 ms 10808 KB Output is correct
25 Correct 169 ms 10808 KB Output is correct
26 Correct 165 ms 10956 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 7 ms 1260 KB Output is correct
37 Correct 52 ms 6892 KB Output is correct
38 Correct 53 ms 6892 KB Output is correct
39 Correct 52 ms 6784 KB Output is correct
40 Correct 52 ms 6764 KB Output is correct
41 Correct 51 ms 6764 KB Output is correct
42 Correct 47 ms 6124 KB Output is correct
43 Correct 57 ms 7200 KB Output is correct
44 Correct 53 ms 6892 KB Output is correct
45 Correct 51 ms 6892 KB Output is correct
46 Correct 56 ms 7148 KB Output is correct
47 Correct 26 ms 1772 KB Output is correct
48 Correct 293 ms 10692 KB Output is correct
49 Correct 279 ms 10564 KB Output is correct
50 Correct 290 ms 10564 KB Output is correct
51 Correct 267 ms 10456 KB Output is correct
52 Correct 258 ms 10444 KB Output is correct
53 Correct 242 ms 10328 KB Output is correct
54 Correct 288 ms 11204 KB Output is correct
55 Correct 311 ms 10692 KB Output is correct
56 Correct 163 ms 10564 KB Output is correct
57 Correct 264 ms 11204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 43 ms 5612 KB Output is correct
11 Correct 54 ms 6836 KB Output is correct
12 Correct 54 ms 6764 KB Output is correct
13 Correct 55 ms 7148 KB Output is correct
14 Correct 56 ms 7148 KB Output is correct
15 Correct 51 ms 5996 KB Output is correct
16 Correct 138 ms 10092 KB Output is correct
17 Correct 133 ms 10060 KB Output is correct
18 Correct 142 ms 10436 KB Output is correct
19 Correct 125 ms 10348 KB Output is correct
20 Correct 163 ms 10788 KB Output is correct
21 Correct 162 ms 10816 KB Output is correct
22 Correct 171 ms 11024 KB Output is correct
23 Correct 162 ms 10820 KB Output is correct
24 Correct 165 ms 10984 KB Output is correct
25 Correct 162 ms 10808 KB Output is correct
26 Correct 169 ms 10808 KB Output is correct
27 Correct 165 ms 10956 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 7 ms 1260 KB Output is correct
38 Correct 52 ms 6892 KB Output is correct
39 Correct 53 ms 6892 KB Output is correct
40 Correct 52 ms 6784 KB Output is correct
41 Correct 52 ms 6764 KB Output is correct
42 Correct 51 ms 6764 KB Output is correct
43 Correct 47 ms 6124 KB Output is correct
44 Correct 57 ms 7200 KB Output is correct
45 Correct 53 ms 6892 KB Output is correct
46 Correct 51 ms 6892 KB Output is correct
47 Correct 56 ms 7148 KB Output is correct
48 Correct 26 ms 1772 KB Output is correct
49 Correct 293 ms 10692 KB Output is correct
50 Correct 279 ms 10564 KB Output is correct
51 Correct 290 ms 10564 KB Output is correct
52 Correct 267 ms 10456 KB Output is correct
53 Correct 258 ms 10444 KB Output is correct
54 Correct 242 ms 10328 KB Output is correct
55 Correct 288 ms 11204 KB Output is correct
56 Correct 311 ms 10692 KB Output is correct
57 Correct 163 ms 10564 KB Output is correct
58 Correct 264 ms 11204 KB Output is correct
59 Correct 157 ms 6508 KB Output is correct
60 Correct 275 ms 10728 KB Output is correct
61 Correct 296 ms 10956 KB Output is correct
62 Correct 301 ms 11204 KB Output is correct
63 Correct 166 ms 11332 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 1 ms 364 KB Output is correct
68 Correct 1 ms 364 KB Output is correct
69 Correct 1 ms 364 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 2 ms 364 KB Output is correct
74 Correct 86 ms 8996 KB Output is correct
75 Correct 52 ms 6912 KB Output is correct
76 Correct 52 ms 6892 KB Output is correct
77 Correct 58 ms 7404 KB Output is correct
78 Correct 85 ms 7404 KB Output is correct
79 Correct 65 ms 6124 KB Output is correct
80 Correct 74 ms 7788 KB Output is correct
81 Correct 93 ms 10092 KB Output is correct
82 Correct 102 ms 10860 KB Output is correct
83 Correct 120 ms 11500 KB Output is correct
84 Correct 53 ms 6932 KB Output is correct
85 Correct 101 ms 10624 KB Output is correct
86 Correct 68 ms 4332 KB Output is correct
87 Correct 288 ms 10576 KB Output is correct
88 Correct 280 ms 10596 KB Output is correct
89 Correct 206 ms 10500 KB Output is correct
90 Correct 233 ms 10220 KB Output is correct
91 Correct 231 ms 10180 KB Output is correct
92 Correct 228 ms 10888 KB Output is correct
93 Correct 322 ms 11884 KB Output is correct
94 Correct 273 ms 12396 KB Output is correct
95 Correct 370 ms 12780 KB Output is correct
96 Correct 166 ms 10692 KB Output is correct
97 Correct 242 ms 11540 KB Output is correct