結果

問題 No.330 Eigenvalue Decomposition
ユーザー koyumeishikoyumeishi
提出日時 2015-12-23 13:03:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 77 ms / 5,000 ms
コード長 1,614 bytes
コンパイル時間 894 ms
コンパイル使用メモリ 99,952 KB
実行使用メモリ 9,632 KB
最終ジャッジ日時 2023-10-19 01:45:20
合計ジャッジ時間 2,845 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
6,372 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 31 ms
6,372 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 33 ms
6,372 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 23 ms
5,316 KB
testcase_09 AC 58 ms
7,956 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 19 ms
4,788 KB
testcase_12 AC 75 ms
9,632 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 18 ms
4,524 KB
testcase_15 AC 24 ms
8,576 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 5 ms
4,348 KB
testcase_18 AC 34 ms
8,048 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 6 ms
4,348 KB
testcase_21 AC 77 ms
8,748 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 7 ms
4,348 KB
testcase_24 AC 56 ms
7,956 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 4 ms
4,348 KB
testcase_27 AC 27 ms
8,748 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 12 ms
5,844 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:68:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   68 |                 scanf("%lld%lld%lld", &a[i],&b[i],&c[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <set>
#include <ctime>
#include <random>
using namespace std;
template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;}
template<class T> istream& operator , (istream& is, T& val){ return is >> val;}
template<class T> ostream& operator << (ostream& os, vector<T>& vec){for(int i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"\n":" ");return os;}

class UnionFindTree{
	typedef struct {
		int parent;
		int rank;
	}base_node;
	
	vector<base_node> node;
public:
	UnionFindTree(int n){
		node.resize(n);
		for(int i=0; i<n; i++){
			node[i].parent=i;
			node[i].rank=0;
		}
	}

	int find(int x){
		if(node[x].parent == x) return x;
		else{
			return node[x].parent = find(node[x].parent);
		}
	}
	
	bool same(int x, int y){
		return find(x) == find(y);
	}

	void unite(int x, int y){
		x = find(node[x].parent);
		y = find(node[y].parent);
		if(x==y) return;
		if(node[x].rank < node[y].rank){
			node[x].parent = y;
		}else if(node[x].rank > node[y].rank){
			node[y].parent = x;
		}else{
			node[x].rank++;
			unite(x,y);
		}
	}
};

int main(){
	int n,m;
	cin >> n >> m;
	
	vector<long long> a(m),b(m),c(m);
	UnionFindTree uft(n);
	for(int i=0; i<m; i++){
		scanf("%lld%lld%lld", &a[i],&b[i],&c[i]);
		a[i]--; b[i]--;
		uft.unite(a[i], b[i]);
	}
	set<int> root;
	for(int i=0; i<n; i++){
		root.insert(uft.find(i));
	}
	cout << root.size() << endl;
	return 0;
}
0