結果

問題 No.2200 Weird Shortest Path
ユーザー stoqstoq
提出日時 2022-05-28 10:16:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 2,443 ms
コンパイル使用メモリ 217,812 KB
実行使用メモリ 9,208 KB
最終ジャッジ日時 2023-09-11 07:20:12
合計ジャッジ時間 6,801 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 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,380 KB
testcase_18 AC 47 ms
5,260 KB
testcase_19 AC 81 ms
8,000 KB
testcase_20 AC 76 ms
7,688 KB
testcase_21 AC 31 ms
5,096 KB
testcase_22 AC 43 ms
5,156 KB
testcase_23 AC 82 ms
7,636 KB
testcase_24 AC 16 ms
4,376 KB
testcase_25 AC 78 ms
8,256 KB
testcase_26 AC 82 ms
8,772 KB
testcase_27 AC 29 ms
5,344 KB
testcase_28 AC 62 ms
7,456 KB
testcase_29 AC 82 ms
8,052 KB
testcase_30 AC 81 ms
7,676 KB
testcase_31 AC 50 ms
5,100 KB
testcase_32 AC 83 ms
7,452 KB
testcase_33 AC 83 ms
7,724 KB
testcase_34 AC 83 ms
8,240 KB
testcase_35 AC 84 ms
8,728 KB
testcase_36 AC 84 ms
9,208 KB
testcase_37 AC 83 ms
7,988 KB
testcase_38 AC 83 ms
7,992 KB
testcase_39 AC 43 ms
5,064 KB
testcase_40 AC 66 ms
7,792 KB
testcase_41 AC 38 ms
5,100 KB
testcase_42 AC 65 ms
7,940 KB
testcase_43 AC 89 ms
7,388 KB
testcase_44 AC 90 ms
7,924 KB
testcase_45 AC 89 ms
7,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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<long long, 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);
  long long 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);
  }
  cout << ans << "\n";
}
0