結果
問題 |
No.2200 Weird Shortest Path
|
ユーザー |
|
提出日時 | 2024-03-30 01:51:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 492 bytes |
コンパイル時間 | 2,379 ms |
コンパイル使用メモリ | 208,828 KB |
最終ジャッジ日時 | 2025-02-20 15:49:05 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 44 |
ソースコード
#include<bits/stdc++.h> #include<atcoder/dsu> using namespace std; using ll=long long; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N,M; cin>>N>>M; vector<tuple<ll,int,int>>vt; for(int i=0;i<M;i++){ int a,b; ll w; cin>>a>>b>>w; a--; b--; vt.push_back(make_tuple(w,a,b)); } sort(vt.begin(),vt.end()); atcoder::dsu uf(N); ll ans=0; for(auto[w,a,b]:vt){ if(uf.same(a,b))continue; ans+=w*uf.size(a)*uf.size(b); uf.merge(a,b); } cout<<ans<<"\n"; }