結果

問題 No.1147 土偶Ⅱ
ユーザー ninoinuininoinui
提出日時 2020-08-07 03:07:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,254 bytes
コンパイル時間 2,751 ms
コンパイル使用メモリ 210,008 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 18:05:36
合計ジャッジ時間 3,502 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 3 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 WA -
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 WA -
testcase_22 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class UnionFind {
private:
  int sz;
  vector<int> par, siz;
public:
  UnionFind() {}
  UnionFind(int n) : sz(n), par(sz), siz(sz, 1) {
    iota(par.begin(), par.end(), 0);
  }
  int root(int x) {
    if (par.at(x) == x) return x;
    else return par.at(x) = root(par.at(x));
  }
  void unit(int x,int y) {
    x = root(x), y = root(y);
    if (x == y) return;
    if (siz.at(x) < siz.at(y)) swap(x, y);
    par.at(y) = x;
    siz.at(x) += siz.at(y);
  }
  int size(int x) {
    x = root(x);
    return siz.at(x);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<set<int>> V(N);
  UnionFind UF(N);
  for (int i = 0, a, b; cin >> a >> b; i++) {
    V.at(--a).insert(--b);
    V.at(b).insert(a);
    if (!UF.same(a, b)) UF.unit(a, b);
  }
  int ans = 0;
  auto f = [&](int i, int j) {
    if (V.at(i).count(j)) return true;
    if (UF.same(i, j)) return false;
    return true;
  };
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      if (!f(j, i)) continue;
      for (int k = 0; k < j; k++) {
        if (!f(k, i)) continue;
        if (!f(k, j)) continue;
        ans++;
      }
    }
  }
  cout << ans << "\n";
}
0