結果

問題 No.2642 Don't cut line!
ユーザー t98slidert98slider
提出日時 2024-03-13 02:41:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 4,000 ms
コード長 1,436 bytes
コンパイル時間 2,617 ms
コンパイル使用メモリ 213,568 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-13 02:41:49
合計ジャッジ時間 5,721 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 51 ms
6,548 KB
testcase_02 AC 51 ms
6,548 KB
testcase_03 AC 47 ms
6,548 KB
testcase_04 AC 48 ms
6,548 KB
testcase_05 AC 49 ms
6,548 KB
testcase_06 AC 45 ms
6,548 KB
testcase_07 AC 44 ms
6,548 KB
testcase_08 AC 42 ms
6,548 KB
testcase_09 AC 42 ms
6,548 KB
testcase_10 AC 44 ms
6,548 KB
testcase_11 AC 46 ms
6,548 KB
testcase_12 AC 46 ms
6,548 KB
testcase_13 AC 43 ms
6,548 KB
testcase_14 AC 45 ms
6,548 KB
testcase_15 AC 45 ms
6,548 KB
testcase_16 AC 43 ms
6,548 KB
testcase_17 AC 36 ms
6,548 KB
testcase_18 AC 39 ms
6,548 KB
testcase_19 AC 30 ms
6,548 KB
testcase_20 AC 33 ms
6,548 KB
testcase_21 AC 39 ms
6,548 KB
testcase_22 AC 33 ms
6,548 KB
testcase_23 AC 46 ms
6,548 KB
testcase_24 AC 25 ms
6,548 KB
testcase_25 AC 29 ms
6,548 KB
testcase_26 AC 42 ms
6,548 KB
testcase_27 AC 29 ms
6,548 KB
testcase_28 AC 42 ms
6,548 KB
testcase_29 AC 37 ms
6,548 KB
testcase_30 AC 31 ms
6,548 KB
testcase_31 AC 35 ms
6,548 KB
testcase_32 AC 35 ms
6,548 KB
testcase_33 AC 2 ms
6,548 KB
testcase_34 AC 2 ms
6,548 KB
testcase_35 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct dsu {
    vector<int> parent_or_size, dat;
    public:
    dsu(int n) : parent_or_size(n, -1), dat(n, 1 << 30) {}
    bool merge(int u, int v, int w){
        int x = leader(u), y = leader(v);
        if (x == y) return false;
        if (-parent_or_size[x] < -parent_or_size[y]) swap(x, y);
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        dat[y] = w;
        return true;
    }
    int leader(int v) {
        while(parent_or_size[v] >= 0) v = parent_or_size[v];
        return v;
    }
    int max_edge(int u, int v){
        int ans = 0;
        while(u != v){
            if (dat[u] > dat[v]) swap(u, v);
            ans = dat[u], u = parent_or_size[u];
        }
        return ans;
    }
};
using T = tuple<int,int,int,int>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll C, c = 0;
    int N, K, ans = 0;
    cin >> N >> K >> C;
    vector<T> E(K);
    for(auto &&[u, v, w, p] : E){
        cin >> u >> v >> w >> p;
        u--, v--;
        swap(w, u);
    }
    sort(E.begin(), E.end());
    dsu uf(N);
    for(auto &&[w, v, u, p] : E){
        if(uf.merge(u, v, w)) c += w, N--;
    }
    if(c > C || N != 1){
        cout << -1 << '\n';
        return 0;
    }
    for(auto &&[w, v, u, p] : E){
        if(c - uf.max_edge(u, v) + w <= C) ans = max(ans, p);
    }
    cout << ans << '\n';
}
0