結果
問題 |
No.1147 土偶Ⅱ
|
ユーザー |
![]() |
提出日時 | 2020-08-07 03:07:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,254 bytes |
コンパイル時間 | 2,786 ms |
コンパイル使用メモリ | 212,192 KB |
最終ジャッジ日時 | 2025-01-12 15:38:25 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 WA * 10 |
ソースコード
#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"; }