結果
問題 | No.2200 Weird Shortest Path |
ユーザー | umezo |
提出日時 | 2023-01-30 07:42:41 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 91 ms / 2,000 ms |
コード長 | 1,326 bytes |
コンパイル時間 | 4,125 ms |
コンパイル使用メモリ | 212,380 KB |
実行使用メモリ | 8,656 KB |
最終ジャッジ日時 | 2023-09-12 11:12:58 |
合計ジャッジ時間 | 14,088 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,384 KB |
testcase_04 | AC | 3 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 2 ms
4,380 KB |
testcase_10 | AC | 2 ms
4,376 KB |
testcase_11 | AC | 1 ms
4,376 KB |
testcase_12 | AC | 1 ms
4,376 KB |
testcase_13 | AC | 2 ms
4,376 KB |
testcase_14 | AC | 2 ms
4,380 KB |
testcase_15 | AC | 2 ms
4,376 KB |
testcase_16 | AC | 1 ms
4,380 KB |
testcase_17 | AC | 27 ms
4,748 KB |
testcase_18 | AC | 48 ms
6,536 KB |
testcase_19 | AC | 80 ms
7,000 KB |
testcase_20 | AC | 79 ms
7,580 KB |
testcase_21 | AC | 33 ms
6,000 KB |
testcase_22 | AC | 43 ms
5,588 KB |
testcase_23 | AC | 83 ms
7,844 KB |
testcase_24 | AC | 15 ms
4,376 KB |
testcase_25 | AC | 79 ms
7,100 KB |
testcase_26 | AC | 83 ms
7,584 KB |
testcase_27 | AC | 30 ms
5,480 KB |
testcase_28 | AC | 62 ms
6,800 KB |
testcase_29 | AC | 83 ms
7,672 KB |
testcase_30 | AC | 82 ms
7,156 KB |
testcase_31 | AC | 52 ms
6,396 KB |
testcase_32 | AC | 84 ms
8,580 KB |
testcase_33 | AC | 85 ms
8,596 KB |
testcase_34 | AC | 86 ms
8,584 KB |
testcase_35 | AC | 85 ms
8,464 KB |
testcase_36 | AC | 84 ms
8,568 KB |
testcase_37 | AC | 85 ms
8,532 KB |
testcase_38 | AC | 87 ms
8,656 KB |
testcase_39 | AC | 44 ms
6,904 KB |
testcase_40 | AC | 66 ms
8,440 KB |
testcase_41 | AC | 40 ms
6,952 KB |
testcase_42 | AC | 65 ms
8,500 KB |
testcase_43 | AC | 91 ms
8,656 KB |
testcase_44 | AC | 91 ms
8,568 KB |
testcase_45 | AC | 91 ms
8,464 KB |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; class Dis{ public: vector<ll> rank,p,siz; Dis(int s){ rank.resize(s,0); p.resize(s,0); siz.resize(s,1); rep(i,s) makeSet(i); } void makeSet(int x){ p[x]=x; rank[x]=0; } bool same(int x,int y){ return findSet(x)==findSet(y); } void unite(int x,int y){ if(same(x,y)) return; link(findSet(x),findSet(y)); } void link(int x,int y){ if(rank[x]>rank[y]){ p[y]=x; siz[x]+=siz[y]; } else{ p[x]=y; siz[y]+=siz[x]; if(rank[x]==rank[y]) rank[y]++; } } int findSet(int x){ if(x != p[x]) p[x]=findSet(p[x]); return p[x]; } int size(int x){ return siz[findSet(x)]; } }; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n,m; cin>>n>>m; vector<pair<ll,pair<int,int>>> G(m); rep(i,m){ int a,b; ll w; cin>>a>>b>>w; a--,b--; G[i]={w,{a,b}}; } Dis ds=Dis(n); sort(ALL(G)); ll ans=0,sum=0; rep(i,m){ auto [a,b]=G[i].second; ll w=G[i].first; if(ds.findSet(a)==ds.findSet(b)) continue; ans+=w*ds.size(a)*ds.size(b); ds.unite(a,b); } cout<<ans<<endl; return 0; }