結果

問題 No.330 Eigenvalue Decomposition
ユーザー ciel
提出日時 2015-12-24 00:51:56
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 576 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 35,328 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-18 22:17:01
合計ジャッジ時間 1,758 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:17:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |         scanf("%d%d",&a,&d);
      |         ~~~~~^~~~~~~~~~~~~~
main.cpp:20:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |                 scanf("%d%d%d",&a,&b,&c);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include <vector>
#include <cstdio>
using namespace std;
struct union_find{
int *parent,n;
int root(int a){return parent[a]<0?a:(parent[a]=root(parent[a]));}
union_find(int _n){n=_n;parent=new int[n];for(int i=0;i<n;i++)parent[i]=-1;}
~union_find(){delete []parent;}
void unite(int a,int b){
int x=root(a),y=root(b);if(x==y)return;
parent[x]+=parent[y];
parent[y]=x;
}
};
int main(){
int a,b,c,d;
scanf("%d%d",&a,&d);
union_find uf(a);
for(;d--;){
scanf("%d%d%d",&a,&b,&c);
uf.unite(a-1,b-1);
}
for(c=0,d=uf.n;d--;)c+=uf.parent[d]<0;
printf("%d\n",c);
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0