結果
問題 |
No.556 仁義なきサルたち
|
ユーザー |
|
提出日時 | 2020-05-15 11:05:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 531 bytes |
コンパイル時間 | 2,149 ms |
コンパイル使用メモリ | 191,672 KB |
最終ジャッジ日時 | 2025-01-10 11:05:33 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:14:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | int m; scanf("%d%d",&n,&m); | ~~~~~^~~~~~~~~~~~~~ main.cpp:20:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 20 | int u,v; scanf("%d%d",&u,&v); u--; v--; | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int n,par[10000],sz[10000]; int find(int u){ return par[u]==u?u:par[u]=find(par[u]); } int main(){ int m; scanf("%d%d",&n,&m); rep(u,n){ par[u]=u; sz[u]=1; } rep(i,m){ int u,v; scanf("%d%d",&u,&v); u--; v--; u=find(u); v=find(v); if(u==v) continue; if(sz[u]>sz[v] || (sz[u]==sz[v] && u<v)){ par[v]=u; sz[u]+=sz[v]; } else{ par[u]=v; sz[v]+=sz[u]; } } rep(u,n) printf("%d\n",find(u)+1); return 0; }