結果

問題 No.2072 Anatomy
ユーザー 👑 kmjpkmjp
提出日時 2022-09-16 22:49:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,739 bytes
コンパイル時間 2,045 ms
コンパイル使用メモリ 204,676 KB
実行使用メモリ 8,604 KB
最終ジャッジ日時 2023-08-23 16:21:40
合計ジャッジ時間 4,691 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,184 KB
testcase_01 AC 3 ms
5,188 KB
testcase_02 AC 3 ms
5,196 KB
testcase_03 AC 3 ms
5,220 KB
testcase_04 AC 4 ms
5,196 KB
testcase_05 AC 3 ms
5,276 KB
testcase_06 AC 4 ms
5,232 KB
testcase_07 AC 3 ms
5,188 KB
testcase_08 AC 44 ms
7,464 KB
testcase_09 AC 45 ms
7,656 KB
testcase_10 AC 49 ms
7,488 KB
testcase_11 AC 47 ms
7,664 KB
testcase_12 AC 40 ms
7,124 KB
testcase_13 AC 47 ms
7,816 KB
testcase_14 AC 34 ms
6,924 KB
testcase_15 AC 28 ms
7,064 KB
testcase_16 AC 53 ms
7,820 KB
testcase_17 AC 47 ms
7,780 KB
testcase_18 AC 24 ms
6,596 KB
testcase_19 AC 49 ms
8,052 KB
testcase_20 AC 50 ms
7,800 KB
testcase_21 AC 46 ms
8,084 KB
testcase_22 AC 53 ms
7,796 KB
testcase_23 AC 47 ms
8,068 KB
testcase_24 AC 47 ms
8,308 KB
testcase_25 AC 49 ms
7,860 KB
testcase_26 AC 3 ms
5,276 KB
testcase_27 AC 47 ms
8,604 KB
testcase_28 AC 43 ms
7,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M;
int ma[505050];
int U[202020],V[202020];

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit(int num=um) {int i; FOR(i,num) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<202020> uf;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>U[i]>>V[i];
		U[i]--,V[i]--;
	}
	int ret=0;
	for(i=M-1;i>=0;i--) {
		x=uf[U[i]];
		y=uf[V[i]];
		if(x==y) {
			ma[x]++;
		}
		else {
			ma[x]=ma[y]=max(ma[x],ma[y])+1;
			uf(x,y);
		}
		ret=max(ret,ma[x]);
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0