#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; class UnionFindTree { private: typedef pair T1; typedef int T2; static const T1 INIT_DATA; T1 updateData(T1 prev, T2 x){ return make_pair(prev.first, x); } T1 uniteData(T1 v1, T1 v2){ if(v1 < v2) return make_pair(v1.first + v2.first, v1.second); else return make_pair(v1.first + v2.first, v2.second); } int n; vector parent; // 親ノード vector rank; // 木の高さの上限 vector num; // グループの要素数 vector data; // グループが持つ値 int find(int x){ if(parent[x] == x) return x; else return parent[x] = find(parent[x]); } public: UnionFindTree(int n){ // コンストラクタ this->n = n; parent.resize(n); for(int i=0; i> n >> m; UnionFindTree uft(n+1); for(int i=1; i<=n; ++i) uft.update(i, i); for(int i=0; i> a >> b; uft.unite(a, b); } for(int i=1; i<=n; ++i) cout << uft.getData(i).second << endl; return 0; }