結果
| 問題 |
No.556 仁義なきサルたち
|
| ユーザー |
Tqk
|
| 提出日時 | 2018-09-18 19:14:44 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 4,419 bytes |
| コンパイル時間 | 1,294 ms |
| コンパイル使用メモリ | 161,336 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-18 08:04:04 |
| 合計ジャッジ時間 | 1,836 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
//#include <iostream>//POJ
//#include <vector>
//#include <string>
//#include <iomanip>
//#include <math.h>
//#include <algorithm>
//#include <cstring>
using namespace std;
#define setc cin.tie(0);ios::sync_with_stdio(0)
#define dd(n) cout<<fixed<<setprecision(n)
#define inp(x) (cin>>x,x)
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define repir(i,a,b) for(int i=(a)-1, i##_first=(b); i>=i##_first; --i)
#define repr(i,n) repir(i,n,0)
#define repir_(i,a,b) for(int i=(a), i##_first=(b); i>=i##_first; --i)
#define repr_(i,n) repir_(i,n,0)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define vcsort(v,c) sort((v).begin(),(v).end(),c)
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define mod(a,b) (a<0?a%b+abs(b):a%b)
#define cl(a,b) (a+b-1/b)
//template<typename T> T vpop(vector<T> *v) {
// T res = v->back();
// v->pop_back();
// return res;
//}
//char vpop(string *v) {
// char res = v->back();
// v->pop_back();
// return res;
//}
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define contain(q) !q.empty()
#define cont(q) !q.empty()
//#define qpop(q, a, b) a=q.back().first;b=q.back().second;q.pop()
//#define pqpop(p, a, b) a=q.top().first;b=q.top().second;q.pop()
#define el "\n"
#define sp " "
#define pi 3.14159265358979
#define co(x) cout<<x<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cim(x) {cin>>x;--x;}
#define cim2(a,b) {cin>>a>>b;--a;--b;}
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#define wildcard(T) numeric_limits<T>::min()
#define pb push_back
#define pq priority_queue
#define np next_permutation
#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
const unsigned int bf0 = (1 << 0);
const unsigned int bf1 = (1 << 1);
const unsigned int bf2 = (1 << 2);
const unsigned int bf3 = (1 << 3);
const unsigned int bf4 = (1 << 4);
const unsigned int bf5 = (1 << 5);
const unsigned int bf6 = (1 << 6);
const unsigned int bf7 = (1 << 7);
const int _10j9p7 = 1000000007;
//#define lint long long
typedef long long lint;
typedef vector<int> IV; typedef vector<string> SV;
typedef vector<lint> LIV;
typedef vector<vector<int>> IVV;
typedef pair<int, int> P;typedef pair<lint,lint> LP;
typedef vector<P> PV;typedef vector<LP> LPV;
const int
dx8[8] ={ 0,1,1,1,0,-1,-1,-1 },
dy8[8] ={ 1,1,0,-1,-1,-1,0,1 },
dx9[9] ={ 0,1,1,1,0,0,-1,-1,-1 },
dy9[9] ={ 1,1,0,-1,0,-1,-1,0,1 },
dx5[5] ={ 0,1,0,0,-1 },
dy5[5] ={ 1,0,0,-1,0 },
dx4[4] ={ 0,1,0,-1 },
dy4[4] ={ 1,0,-1,0 };
template<class... A> void cim_(A... args) {
for (lint *i : initializer_list<lint*>{ args... }) {
cin>>*i;--*i;
}
return;
}
template<class T>inline bool maxi(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool mini(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define MAX_N 10000
class UnionFind{
public:
int par[MAX_N];//ne no bangou"parent"
int sum[MAX_N];//[根]にだけそのグループの個数が入っている
void init(int n){
rep(i, n){
par[i]=i;
sum[i]=1;
}
}
UnionFind(int n){
init(n);
}
UnionFind(){
}
int root(int x){
if (par[x]==x)return x;
else return par[x]=root(par[x]);//keiro asshuku
}
bool same(int x, int y){//入力--した?
return this->root(x)==this->root(y);
}
void unite(int x, int y){//xの親にyの親をつける
x=root(x);
y=root(y);
if (x==y)return;
par[y]=x;
sum[x]=sum[x]+sum[y];
}
};
UnionFind t;
int main(){
setc;
lint n,m;cin>>n>>m;t.init(n);
lint in1,in2;
rep(i, m){
cim2(in1,in2);
if(t.sum[t.root(in1)]<t.sum[t.root(in2)]||(t.sum[t.root(in1)]==t.sum[t.root(in2)]&&t.root(in1)>t.root(in2)))swap(in1,in2);
t.unite(in1,in2);
}rep(i, n){
co(t.root(i)+1);
}
gc();
}
Tqk