結果
| 問題 | No.3087 University Coloring | 
| コンテスト | |
| ユーザー |  yu23578 | 
| 提出日時 | 2025-04-04 22:53:13 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 251 ms / 2,000 ms | 
| コード長 | 572 bytes | 
| コンパイル時間 | 2,154 ms | 
| コンパイル使用メモリ | 210,544 KB | 
| 実行使用メモリ | 12,180 KB | 
| 最終ジャッジ日時 | 2025-04-04 22:53:24 | 
| 合計ジャッジ時間 | 9,922 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 33 | 
ソースコード
#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
#define int long long
int N,M;
int ans = 0;
vector<tuple<int,int,int>> G;
vector<bool> visited(200001);
signed main(){
  cin>>N>>M;
  dsu d(N+1);
  for(int i = 0; i < M; i++){
    int a,b,c; cin>>a>>b>>c;
    G.push_back(make_tuple(c,a,b));
  }
  sort(G.rbegin(),G.rend());
  for(int i = 0; i < M; i++){
    int a = get<1>(G[i]);
    int b = get<2>(G[i]);
    int c = get<0>(G[i]);
    if(!d.same(a,b)){
      d.merge(a,b);
      ans += c;
    }
  }
  cout << ans*2 << endl;
}
            
            
            
        