結果
問題 |
No.2200 Weird Shortest Path
|
ユーザー |
![]() |
提出日時 | 2022-05-30 05:59:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 104 ms / 2,000 ms |
コード長 | 689 bytes |
コンパイル時間 | 2,343 ms |
コンパイル使用メモリ | 213,152 KB |
最終ジャッジ日時 | 2025-01-29 17:03:16 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 44 |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/dsu> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<tuple<__int128, int, int>> edges; for (int i = 0; i < m; i++) { int a, b, w; cin >> a >> b >> w; a--, b--; edges.push_back({w, a, b}); } sort(begin(edges), end(edges)); atcoder::dsu uf(n); __int128 ans = 0; for (auto [w, a, b] : edges) { if (uf.same(a, b)) continue; ans += w * uf.size(a) * uf.size(b); uf.merge(a, b); } assert(ans <= 1e18); cout << (long long) ans << "\n"; }