結果

問題 No.1316 Maximum Minimum Spanning Tree
ユーザー optopt
提出日時 2020-11-28 15:40:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,566 bytes
コンパイル時間 7,971 ms
コンパイル使用メモリ 313,492 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 02:11:57
合計ジャッジ時間 13,836 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 RE -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
testcase_69 RE -
testcase_70 RE -
testcase_71 RE -
testcase_72 RE -
testcase_73 RE -
testcase_74 RE -
testcase_75 RE -
testcase_76 RE -
testcase_77 RE -
testcase_78 RE -
testcase_79 RE -
testcase_80 RE -
testcase_81 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)

const int MIN_N = 2;
const int MAX_N = 100;
const int MAX_M = 100;
const int MIN_D = 1;
const int MAX_D = 1e8;
const int MIN_c = 1;
const int MAX_c = 1e8;
const int MIN_d = 1;
const int MAX_d = 1e8;


struct UnionFind {
  vector<int> d;
  int m; // number of connected components
  UnionFind(int n = 0) : d(n, -1), m(n) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    --m;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};


signed main(int argc, char* argv[]) {
  registerValidation(argc, argv);
  int N = inf.readInt(MIN_N, MAX_N, "N");
  inf.readSpace();
  int M = inf.readInt(N-1, MAX_M, "M");
  inf.readSpace();
  int D = inf.readInt(MIN_D, MAX_D, "D");
  inf.readEoln();

  set<pair<int, int>> S;
  UnionFind uf(N);

  rep(i, M) {
    int a = inf.readInt(1, N, "a");
    inf.readSpace();
    int b = inf.readInt(1, N, "b");
    inf.readSpace();
    int c = inf.readInt(MIN_c, MAX_c, "c");
    inf.readSpace();
    int d = inf.readInt(MIN_d, MAX_d, "d");
    inf.readEoln();

    assert(S.find({a, b}) == S.end());
    assert(S.find({b, a}) == S.end());
    S.emplace(a, b);
    uf.unite(a, b);
  }
  assert(uf.m == 1);
  inf.readEof();
}
0