답안 #777882

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
777882 2023-07-09T21:06:53 Z t6twotwo 자매 도시 (APIO20_swap) C++17
37 / 100
2000 ms 10864 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> w, f, up, p;
int find(int x) {
    return x == p[x] ? x : p[x] = find(p[x]);
}
constexpr int inf = 2e9;
void init(int n, int m, vector<int> U, vector<int> V, vector<int> W) {
    N = n;
    M = m;
    p.resize(N);
    iota(p.begin(), p.end(), 0);
    vector<tuple<int, int, int>> edges(M);
    for (int i = 0; i < M; i++) {
        edges[i] = {W[i], U[i], V[i]};
    }
    sort(edges.begin(), edges.end());
    up.resize(N, -1);
    f.resize(N);
    w.resize(N, inf);
    int K = N;
    vector<int> deg(N);
    for (auto [z, a, b] : edges) {
        int x = find(a);
        int y = find(b);
        if (x == y) {
            if (!f[x]) {
                f[x] = 1;
                w[x] = z;
            }
            continue;
        }
        f.push_back(f[x] | f[y]);
        w.push_back(z);
        if (++deg[a] == 3 || ++deg[b] == 3) {
            f[K] = 1;
        }
        p.push_back(K);
        up.push_back(-1);
        p[x] = p[y] = up[x] = up[y] = K++;
    }
}
int getMinimumFuelCapacity(int x, int y) {
    if (find(x) != find(y)) {
        return -1;
    }
    while (x != y) {
        if (x < y) {
            x = up[x];
        } else {
            y = up[y];
        }
    }
    int ans = inf;
    while (x != -1) {
        if (f[x]) {
            ans = min(ans, w[x]);
        }
        x = up[x];
    }
    if (ans == inf) {
        ans = -1;
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 29 ms 5760 KB Output is correct
10 Correct 37 ms 6968 KB Output is correct
11 Correct 42 ms 6964 KB Output is correct
12 Correct 36 ms 7332 KB Output is correct
13 Correct 36 ms 7852 KB Output is correct
14 Correct 37 ms 5928 KB Output is correct
15 Correct 125 ms 8624 KB Output is correct
16 Correct 125 ms 8396 KB Output is correct
17 Correct 142 ms 8816 KB Output is correct
18 Execution timed out 2081 ms 9404 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Execution timed out 2075 ms 8444 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 29 ms 5760 KB Output is correct
11 Correct 37 ms 6968 KB Output is correct
12 Correct 42 ms 6964 KB Output is correct
13 Correct 36 ms 7332 KB Output is correct
14 Correct 36 ms 7852 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 6 ms 1364 KB Output is correct
35 Correct 34 ms 7264 KB Output is correct
36 Correct 35 ms 7340 KB Output is correct
37 Correct 34 ms 7328 KB Output is correct
38 Correct 34 ms 7216 KB Output is correct
39 Correct 34 ms 7220 KB Output is correct
40 Correct 32 ms 6628 KB Output is correct
41 Correct 36 ms 7248 KB Output is correct
42 Correct 35 ms 7332 KB Output is correct
43 Correct 34 ms 7264 KB Output is correct
44 Correct 37 ms 7348 KB Output is correct
45 Correct 58 ms 8220 KB Output is correct
46 Correct 34 ms 7336 KB Output is correct
47 Correct 35 ms 7332 KB Output is correct
48 Correct 41 ms 7640 KB Output is correct
49 Correct 48 ms 5872 KB Output is correct
50 Correct 38 ms 4792 KB Output is correct
51 Correct 47 ms 7076 KB Output is correct
52 Correct 57 ms 9448 KB Output is correct
53 Correct 63 ms 10056 KB Output is correct
54 Correct 68 ms 10864 KB Output is correct
55 Correct 33 ms 7340 KB Output is correct
56 Correct 64 ms 9840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 29 ms 5760 KB Output is correct
10 Correct 37 ms 6968 KB Output is correct
11 Correct 42 ms 6964 KB Output is correct
12 Correct 36 ms 7332 KB Output is correct
13 Correct 36 ms 7852 KB Output is correct
14 Correct 37 ms 5928 KB Output is correct
15 Correct 125 ms 8624 KB Output is correct
16 Correct 125 ms 8396 KB Output is correct
17 Correct 142 ms 8816 KB Output is correct
18 Execution timed out 2081 ms 9404 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 29 ms 5760 KB Output is correct
11 Correct 37 ms 6968 KB Output is correct
12 Correct 42 ms 6964 KB Output is correct
13 Correct 36 ms 7332 KB Output is correct
14 Correct 36 ms 7852 KB Output is correct
15 Correct 37 ms 5928 KB Output is correct
16 Correct 125 ms 8624 KB Output is correct
17 Correct 125 ms 8396 KB Output is correct
18 Correct 142 ms 8816 KB Output is correct
19 Execution timed out 2081 ms 9404 KB Time limit exceeded
20 Halted 0 ms 0 KB -