結果

問題 No.3087 University Coloring
ユーザー t98slider
提出日時 2025-04-04 22:52:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 529 bytes
コンパイル時間 4,439 ms
コンパイル使用メモリ 259,112 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2025-04-04 22:52:15
合計ジャッジ時間 8,559 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<tuple<int,int,int>> edge(m);
    for(auto &&[u, v, w] : edge){
        cin >> u >> v >> w;
        swap(u, w);
    }
    sort(edge.rbegin(), edge.rend());
    atcoder::dsu uf(n + 1);
    long long ans = 0;
    for(auto &&[w, u, v] : edge){
        if(uf.same(u, v)) continue;
        ans += w;
        uf.merge(u, v);
    }
    cout << 2 * ans << '\n';
}
0