結果
| 問題 |
No.2072 Anatomy
|
| コンテスト | |
| ユーザー |
srjywrdnprkt
|
| 提出日時 | 2023-05-08 23:03:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,566 bytes |
| コンパイル時間 | 1,035 ms |
| コンパイル使用メモリ | 111,096 KB |
| 最終ジャッジ日時 | 2025-02-12 21:03:46 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 19 WA * 8 |
ソースコード
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
using namespace std;
struct UnionFind {
vector<long long> par;
vector<long long> siz;
UnionFind(long long N) : par(N), siz(N) {
for(long long i = 0; i < N; i++){
par[i] = i;
siz[i] = 1;
}
}
long long root(long long x) {
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
long long unite(long long x, long long y) {
long long rx = root(x);
long long ry = root(y);
if (rx == ry) return rx;
if (siz[rx] > siz[ry]) swap(rx, ry);
par[rx] = ry;
siz[ry] += siz[rx];
return ry;
}
bool same(long long x, long long y) {
long long rx = root(x);
long long ry = root(y);
return rx == ry;
}
long long size(long long x){
return siz[root(x)];
}
};
int main(){
int N, M, mx=0;
cin >> N >> M;
vector<int> u(M), v(M);
for (int i=0; i<M; i++) cin >> u[i] >> v[i];
UnionFind tree(N+1);
vector<int> ans(N+1);
for (int i=M-1; i>=0; i--){
if (tree.same(u[i], v[i])) ans[tree.root(u[i])]++;
else{
tree.unite(u[i], v[i]);
ans[tree.root(u[i])] = max(ans[tree.root(u[i])], ans[tree.root(v[i])])+1;
}
}
for (int i=1; i<=N; i++) mx = max(mx, ans[i]);
cout << mx << endl;
return 0;
}
srjywrdnprkt