답안 #1029939

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1029939 2024-07-21T14:12:12 Z VMaksimoski008 자매 도시 (APIO20_swap) C++17
37 / 100
2000 ms 13648 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using Edge = array<int, 3>;

const int maxn = 1e5 + 5;

struct DSU {
    int n;
    vector<int> par, size;

    DSU(int _n) {
        n = _n + 1;
        par.resize(n+1);
        size.resize(n+1, 1);
        for(int i=1; i<=n; i++) par[i] = i;
    }

    int find(int u) {
        if(u == par[u]) return u;
        return par[u] = find(par[u]);
    }

    bool uni(int a, int b) {
        a = find(a), b = find(b);
        if(a == b) return 0;
        if(size[a] < size[b]) swap(a, b);
        size[a] += size[b];
        par[b] = a;
        return 1;
    }

    bool same_set(int a, int b) { return find(a) == find(b); }
};

int n, m;
vector<Edge> edges;

void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
    n = N; m = M;
    for(int i=0; i<m; i++) edges.push_back({ U[i], V[i], W[i] });
    sort(edges.begin(), edges.end(), [&](Edge &a, Edge &b) { return a[2] < b[2]; });
}

int getMinimumFuelCapacity(int X, int Y) {
    int l=2, r=m-1, ans=-1;

    while(l <= r) {
        int mid = (l + r) / 2;
        DSU dsu(n);

        vector<int> deg(n);

        for(int i=0; i<=mid; i++) {
            dsu.uni(edges[i][0], edges[i][1]);
            deg[edges[i][0]]++; deg[edges[i][1]]++;
        }

        bool line = false;
        vector<int> cnt(n);
        int mx = 0;

        for(int i=0; i<n; i++) {
            if(dsu.find(i) != dsu.find(X)) continue;
            cnt[deg[i]]++;
            mx = max(mx, deg[i]);
        }

        if(mx <= 2 && cnt[1] == 2) line = 1;

        if(dsu.same_set(X, Y) && !line) ans = mid, r = mid - 1;
        else l = mid + 1;
    }

    return (ans == -1 ? ans : edges[ans][2]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 444 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 96 ms 5584 KB Output is correct
10 Correct 239 ms 6348 KB Output is correct
11 Correct 258 ms 6188 KB Output is correct
12 Correct 266 ms 6488 KB Output is correct
13 Correct 227 ms 6524 KB Output is correct
14 Execution timed out 2056 ms 5832 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Execution timed out 2016 ms 10320 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 444 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 448 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 452 KB Output is correct
24 Correct 3 ms 604 KB Output is correct
25 Correct 2 ms 644 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 444 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 96 ms 5584 KB Output is correct
11 Correct 239 ms 6348 KB Output is correct
12 Correct 258 ms 6188 KB Output is correct
13 Correct 266 ms 6488 KB Output is correct
14 Correct 227 ms 6524 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 448 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 2 ms 620 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 452 KB Output is correct
29 Correct 3 ms 604 KB Output is correct
30 Correct 2 ms 644 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 2 ms 344 KB Output is correct
34 Correct 10 ms 1308 KB Output is correct
35 Correct 326 ms 6172 KB Output is correct
36 Correct 319 ms 6200 KB Output is correct
37 Correct 303 ms 6212 KB Output is correct
38 Correct 335 ms 6128 KB Output is correct
39 Correct 316 ms 6192 KB Output is correct
40 Correct 245 ms 5836 KB Output is correct
41 Correct 299 ms 6456 KB Output is correct
42 Correct 335 ms 6200 KB Output is correct
43 Correct 212 ms 6168 KB Output is correct
44 Correct 368 ms 6488 KB Output is correct
45 Correct 269 ms 9948 KB Output is correct
46 Correct 306 ms 6220 KB Output is correct
47 Correct 281 ms 6212 KB Output is correct
48 Correct 290 ms 6632 KB Output is correct
49 Correct 46 ms 11472 KB Output is correct
50 Correct 59 ms 7112 KB Output is correct
51 Correct 183 ms 7812 KB Output is correct
52 Correct 316 ms 12156 KB Output is correct
53 Correct 245 ms 11464 KB Output is correct
54 Correct 305 ms 13648 KB Output is correct
55 Correct 207 ms 6168 KB Output is correct
56 Correct 345 ms 12276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 444 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 96 ms 5584 KB Output is correct
10 Correct 239 ms 6348 KB Output is correct
11 Correct 258 ms 6188 KB Output is correct
12 Correct 266 ms 6488 KB Output is correct
13 Correct 227 ms 6524 KB Output is correct
14 Execution timed out 2056 ms 5832 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 444 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 96 ms 5584 KB Output is correct
11 Correct 239 ms 6348 KB Output is correct
12 Correct 258 ms 6188 KB Output is correct
13 Correct 266 ms 6488 KB Output is correct
14 Correct 227 ms 6524 KB Output is correct
15 Execution timed out 2056 ms 5832 KB Time limit exceeded
16 Halted 0 ms 0 KB -