結果

問題 No.330 Eigenvalue Decomposition
ユーザー pekempeypekempey
提出日時 2015-12-23 00:10:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 64 ms / 5,000 ms
コード長 1,344 bytes
コンパイル時間 2,196 ms
コンパイル使用メモリ 162,052 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 23:22:36
合計ジャッジ時間 3,303 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 28 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 31 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 21 ms
4,348 KB
testcase_09 AC 54 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 18 ms
4,348 KB
testcase_12 AC 60 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 17 ms
4,348 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 12 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 4 ms
4,348 KB
testcase_21 AC 64 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 5 ms
4,348 KB
testcase_24 AC 53 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 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 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:42:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   42 |                 scanf("%d %d %d", &a, &b, &c);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define FILL(a, b, T) fill_n((T *)a, sizeof(a) / sizeof(T), b)
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
using ll = long long;

struct UF {
	vector<int> parent, size;
	UF(int n) : parent(n), size(n, 1) {
		rep (i, n) parent[i] = i;
	}
	int root(int x) {
		if (x == parent[x]) return x;
		else return parent[x] = root(parent[x]);
	}
	void merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return;
		if (size[x] < size[y]) swap(x, y);
		size[x] += size[y];
		parent[y] = x;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	UF uf(N);
	rep (i, M) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		uf.merge(a - 1, b - 1);
	}
	int ans = 0;
	rep (i, N) if (uf.root(i) == i) {
		ans++;
	}
	cout << ans << endl;
	return 0;
}
0