結果
| 問題 | No.3087 University Coloring | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-04-04 22:10:31 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 248 ms / 2,000 ms | 
| コード長 | 641 bytes | 
| コンパイル時間 | 5,774 ms | 
| コンパイル使用メモリ | 333,488 KB | 
| 実行使用メモリ | 9,472 KB | 
| 最終ジャッジ日時 | 2025-04-04 22:11:03 | 
| 合計ジャッジ時間 | 13,726 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 33 | 
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
int main()
{
    int n,m;
    cin>>n>>m;
    vector<ll> a(m),b(m),c(m);
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i]>>c[i];
        a[i]--;b[i]--;
    }
    vector<int> idx(m);
    for(int i=0;i<m;i++)idx[i]=i;
    sort(idx.begin(),idx.end(),[&](int x,int y)->bool{
        return c[x]>c[y];
    });
    dsu uf(n);
    ll ans=0;
    for(int i=0;i<m;i++){
        int t=idx[i];
        if(!uf.same(a[t],b[t])){
            ans+=c[t]*2;
            uf.merge(a[t],b[t]);
        }
    }
    cout<<ans<<endl;
    return 0;
}
            
            
            
        