結果

問題 No.1639 最小通信路
ユーザー k1suxuk1suxu
提出日時 2021-08-12 15:21:16
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,013 bytes
コンパイル時間 3,117 ms
コンパイル使用メモリ 281,344 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 19:54:26
合計ジャッジ時間 4,349 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i = (int)a; i < (int)b; i++)
#define pb push_back
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vvll vector<vll>
#define vs vector<string>
#define vvs vector<vs>
#define vc vector<char>
#define vvc vector<vc>
#define pii pair<int,int>
#define pllll pair<ll,ll>
#define vpii vector<pair<int,int>>
#define vpllll vector<pair<ll,ll>>
#define vpis vector<pair<int,string>>
#define vplls vector<pair<ll, string>>
#define vpsi vector<pair<string, int>>
#define vpsll vector<pair<string, ll>>

#define int ll

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const ll INF = 1e15;

struct UnionFind {
    vi r;

    UnionFind(int n) {
        r = vi(n, -1);
    }

    int root(int x) {
        if(r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }
};

struct edge {
    int from;
    int to;
    int cost;

    bool operator<(edge &x) {
        return cost < x.cost;
    }
};

void solve() {
    int n;
    cin >> n;
    int m = n * (n - 1) / 2;
    vector<edge> g(m);
    UnionFind UF(n);
    FOR(m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        g[i] = {a, b, c};
    }
    int ans = 0;
    for(auto e : g) {
        if(!UF.issame(e.from, e.to)) {
            ans = e.cost;
            UF.unite(e.from, e.to);
        }
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}
0