結果
| 問題 |
No.2072 Anatomy
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2022-09-16 21:29:07 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 131 ms / 2,000 ms |
| コード長 | 753 bytes |
| コンパイル時間 | 1,686 ms |
| コンパイル使用メモリ | 169,524 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-21 18:26:22 |
| 合計ジャッジ時間 | 5,385 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct unionfind{
vector<int> a;
vector<int> p;
unionfind(int N): a(N, 0), p(N, -1){
}
int root(int x){
if (p[x] == -1){
return x;
} else {
p[x] = root(p[x]);
return p[x];
}
}
void unite(int x, int y){
x = root(x);
y = root(y);
if (x != y){
p[y] = x;
a[x] = max(a[x], a[y]);
}
a[x]++;
}
};
int main(){
int N, M;
cin >> N >> M;
vector<int> u(M), v(M);
for (int i = 0; i < M; i++){
cin >> u[i] >> v[i];
u[i]--;
v[i]--;
}
unionfind UF(N);
for (int i = M - 1; i >= 0; i--){
UF.unite(u[i], v[i]);
}
int ans = 0;
for (int i = 0; i < N; i++){
ans = max(ans, UF.a[i]);
}
cout << ans << endl;
}
SSRS