結果
問題 | No.330 Eigenvalue Decomposition |
ユーザー |
![]() |
提出日時 | 2015-12-19 17:10:57 |
言語 | C++11 (gcc 13.3.0) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 578 bytes |
コンパイル時間 | 119 ms |
コンパイル使用メモリ | 23,680 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-16 16:08:42 |
合計ジャッジ時間 | 5,017 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 WA * 1 |
other | AC * 4 RE * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:22:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 22 | scanf("%d%d",&n,&m); | ~~~~~^~~~~~~~~~~~~~ main.cpp:26:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 26 | scanf("%d%d",&a,&b); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <cstdio> #define rep(i,n) for(int i=0;i<n;++i) using namespace std; const int nmax=100010; int par[nmax],rnk[nmax]; void init(int n){rep(i,n) par[i]=i,rnk[i]=0;} int find(int x){return (par[x]==x)?x:par[x]=find(par[x]);} void unite(int a,int b){ a=find(a),b=find(b); if(a==b) return; if(rnk[a]<rnk[b]) par[a]=b; else{ par[b]=a; if(rnk[a]==rnk[b]) rnk[a]++; } } int main(void){ int n,m; scanf("%d%d",&n,&m); init(n); while(m--){ int a,b; scanf("%d%d",&a,&b); unite(a,b); } int ans=0; rep(i,n) ans+=(i==par[i]); printf("%d\n",ans); return 0; }