結果

問題 No.2642 Don't cut line!
ユーザー t98slidert98slider
提出日時 2024-03-13 03:03:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 4,000 ms
コード長 1,108 bytes
コンパイル時間 3,189 ms
コンパイル使用メモリ 214,176 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-13 03:03:38
合計ジャッジ時間 6,710 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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, i = 0;
    cin >> N >> K >> C;
    vector<int> ps(N, -1), d(N, 1 << 30), mx(K);
    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());
    for(auto [w, v, u, p] : E){
        while(u != v){
            if(d[v] > d[u]) swap(v, u);
            if(ps[v] < 0){
                N--;
                c += w;
                mx[i] = w;
                while(ps[u] >= u) u = ps[u];
                if(-ps[v] < -ps[u]) swap(u, v);
                ps[v] += ps[u];
                ps[u] = v;
                d[u] = w;
                break;
            }
            mx[i] = d[v], v = ps[v];
        }
        i++;
    }
    if(c > C || N != 1){
        cout << -1 << '\n';
        exit(0);
    }
    i = 0;
    for(auto [w, v, u, p] : E) if(c + w - mx[i++] <= C) ans = max(ans, p);
    cout << ans << '\n';
}
0