結果

問題 No.556 仁義なきサルたち
ユーザー WA_TLEWA_TLE
提出日時 2017-08-11 22:40:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,370 bytes
コンパイル時間 1,307 ms
コンパイル使用メモリ 124,276 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 22:54:13
合計ジャッジ時間 2,071 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 8 ms
6,940 KB
testcase_14 AC 9 ms
6,940 KB
testcase_15 AC 10 ms
6,944 KB
testcase_16 AC 16 ms
6,940 KB
testcase_17 AC 17 ms
6,944 KB
testcase_18 AC 20 ms
6,940 KB
testcase_19 AC 19 ms
6,940 KB
testcase_20 AC 20 ms
6,940 KB
testcase_21 AC 21 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int mod=1000000007;
const int big=1e9+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-9;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}

int main(void){
	int n,m,i,j,a,b;cin>>n>>m;
	vector<int>boss(n);//自分のうえ
	vector<int>num(n);
	for(i=0;i<n;i++){boss[i]=i;num[i]=1;}
	for(i=0;i<m;i++){
		cin>>a>>b;a--;b--;
		while(boss[a]!=a){a=boss[a];}
		while(boss[b]!=b){b=boss[b];}
		if(a==b){continue;}
		if(num[a]<num[b]){swap(a,b);}
		else if(num[a]==num[b]&&a>b){swap(a,b);}
		//aがかつ
		num[a]+=num[b];
		boss[b]=a;
	}
	for(i=0;i<n;i++){
		a=i;
		while(boss[a]!=a){a=boss[a];}
		cout<<a+1<<endl;
	}
	return 0;
}
0