結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 62 ms
4,380 KB
testcase_18 AC 109 ms
5,132 KB
testcase_19 AC 193 ms
7,812 KB
testcase_20 AC 183 ms
7,548 KB
testcase_21 AC 71 ms
5,084 KB
testcase_22 AC 100 ms
5,144 KB
testcase_23 AC 195 ms
7,532 KB
testcase_24 AC 34 ms
4,376 KB
testcase_25 AC 186 ms
8,964 KB
testcase_26 AC 194 ms
7,568 KB
testcase_27 AC 67 ms
5,076 KB
testcase_28 AC 146 ms
8,276 KB
testcase_29 AC 196 ms
8,904 KB
testcase_30 AC 194 ms
7,952 KB
testcase_31 AC 119 ms
5,028 KB
testcase_32 AC 198 ms
7,108 KB
testcase_33 AC 197 ms
9,288 KB
testcase_34 AC 197 ms
8,544 KB
testcase_35 AC 197 ms
8,692 KB
testcase_36 AC 197 ms
8,216 KB
testcase_37 AC 197 ms
8,768 KB
testcase_38 AC 198 ms
8,168 KB
testcase_39 AC 99 ms
5,024 KB
testcase_40 AC 154 ms
7,776 KB
testcase_41 AC 88 ms
5,256 KB
testcase_42 AC 144 ms
7,548 KB
testcase_43 AC 208 ms
8,076 KB
testcase_44 AC 209 ms
8,092 KB
testcase_45 AC 208 ms
7,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/dsu>

int main() {
  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