結果
問題 | No.2072 Anatomy |
ユーザー | umimel |
提出日時 | 2022-09-16 21:56:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 137 ms / 2,000 ms |
コード長 | 1,522 bytes |
コンパイル時間 | 1,964 ms |
コンパイル使用メモリ | 172,184 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-12-21 19:45:28 |
合計ジャッジ時間 | 6,111 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; #define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i) #define rep(i, n) drep(i, 0, n - 1) #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll INF = 1LL << 60; const ll MAX_N = 2e5; struct UnionFind{ vector<ll> parent; vector<ll> sizes; vector<ll> cnt; UnionFind(ll N) : parent(N), sizes(N, 1), cnt(N, 0){ rep(i, N) parent[i] = i; } ll root(ll x){ if (parent[x] == x) return x; return parent[x] = root(parent[x]); } void unite(ll x, ll y){ ll rx = root(x); ll ry = root(y); if (rx == ry){ cnt[rx]++; return; } if (sizes[rx] < sizes[ry]) swap(rx, ry); cnt[rx] = max(cnt[rx], cnt[ry])+1; sizes[rx] += sizes[ry]; parent[ry] = rx; } bool same(ll x, ll y){ ll rx = root(x); ll ry = root(y); return rx == ry; } ll size(ll x){ return sizes[root(x)]; } ll count(ll x){ return cnt[root(x)]; } }; int main(){ ll n, m; cin >> n >> m; vector<pll> e(m); rep(i, m){ ll u, v; cin >> u >> v; u--; v--; e[i] = {u, v}; } UnionFind UF(n); for(ll i=m-1; i>=0; i--){ UF.unite(e[i].fi, e[i].se); } cout << UF.count(0) << endl; }