結果
問題 | No.2072 Anatomy |
ユーザー |
|
提出日時 | 2022-09-16 22:25:58 |
言語 | C++17 (gcc 11.2.0 + boost 1.78.0) |
結果 |
AC
|
実行時間 | 48 ms / 2,000 ms |
コード長 | 2,713 bytes |
コンパイル時間 | 1,795 ms |
使用メモリ | 8,640 KB |
最終ジャッジ日時 | 2023-01-11 07:40:49 |
合計ジャッジ時間 | 4,815 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,904 KB |
testcase_01 | AC | 1 ms
4,900 KB |
testcase_02 | AC | 1 ms
4,904 KB |
testcase_03 | AC | 2 ms
6,952 KB |
testcase_04 | AC | 2 ms
4,908 KB |
testcase_05 | AC | 1 ms
4,900 KB |
testcase_06 | AC | 1 ms
4,900 KB |
testcase_07 | AC | 1 ms
6,952 KB |
testcase_08 | AC | 41 ms
7,764 KB |
testcase_09 | AC | 39 ms
8,108 KB |
testcase_10 | AC | 40 ms
6,680 KB |
testcase_11 | AC | 41 ms
7,852 KB |
testcase_12 | AC | 32 ms
6,480 KB |
testcase_13 | AC | 45 ms
8,336 KB |
testcase_14 | AC | 28 ms
5,864 KB |
testcase_15 | AC | 26 ms
6,948 KB |
testcase_16 | AC | 47 ms
8,300 KB |
testcase_17 | AC | 41 ms
8,376 KB |
testcase_18 | AC | 21 ms
6,004 KB |
testcase_19 | AC | 47 ms
8,564 KB |
testcase_20 | AC | 47 ms
8,592 KB |
testcase_21 | AC | 42 ms
8,608 KB |
testcase_22 | AC | 47 ms
8,616 KB |
testcase_23 | AC | 44 ms
8,504 KB |
testcase_24 | AC | 42 ms
8,616 KB |
testcase_25 | AC | 48 ms
8,640 KB |
testcase_26 | AC | 2 ms
4,900 KB |
testcase_27 | AC | 42 ms
8,524 KB |
testcase_28 | AC | 40 ms
8,592 KB |
ソースコード
#include <bits/stdc++.h> using namespace std ; #define fast_input_output ios::sync_with_stdio(false); cin.tie(nullptr); typedef long long ll ; typedef long double ld ; typedef pair<ll,ll> P ; typedef tuple<ll,ll,ll> TP ; #define chmin(a,b) a = min(a,b) #define chmax(a,b) a = max(a,b) #define bit_count(x) __builtin_popcountll(x) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) a / gcd(a,b) * b #define rep(i,n) for(int i = 0 ; i < n ; i++) #define rrep(i,a,b) for(int i = a ; i < b ; i++) #define endl "\n" struct UnionFind { private: vector<int> par ; //親 vector<int> lank ; //木の深さ vector<int> volume ; //構成する集合のサイズ vector<int> edge ; //構成する集合の辺の数 vector<int> value; public: UnionFind(int n){ //n要素で初期化 par.resize(n) ; lank.resize(n) ; volume.resize(n) ; edge.resize(n) ; value.resize(n) ; for(int i = 0 ; i < n ; i++){ par[i] = i ; lank[i] = 0 ; volume[i] = 1 ; edge[i] = 0 ; value[i] = 0; } } //木の根を求める int root(int x) { if(par[x] == x) return x ; else return par[x] = root(par[x]) ; } //xとyの属する集合を合併 void unite(int x , int y){ x = root(x); y = root(y) ; if(x == y) { edge[x]++ ; value[x] = max(value[x],value[y]) + 1; return ; } if(lank[x] < lank[y]){ par[x] = y ; volume[y] += volume[x] ; edge[y] += edge[x] + 1 ; value[y] = max(value[x],value[y]) + 1; } else { par[y] = x ; volume[x] += volume[y] ; edge[x] += edge[y] + 1 ; value[x] = max(value[x],value[y]) + 1; if(lank[x] == lank[y]) lank[x]++ ; } } bool same(int x , int y) { return root(x) == root(y) ; } int size(int x) { return volume[root(x)] ; } int edge_num(int x) { return edge[root(x)] ; } int solve(int x) { return value[root(x)] ; } }; int n, m ; pair<int,int> E[202020]; int main(){ fast_input_output cin >> n >> m ; UnionFind uf(n); rep(i,m){ int a, b; cin >> a >> b; a--; b--; E[i] = {a,b}; } for(int i = m - 1 ; i >= 0 ; i--){ auto [a, b] = E[i]; uf.unite(a,b); } int res = 0; rep(i,n) chmax(res,uf.solve(i)); cout << res << endl; }