結果

問題 No.330 Eigenvalue Decomposition
ユーザー 37zigen37zigen
提出日時 2016-05-23 22:32:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,444 ms / 5,000 ms
コード長 1,039 bytes
コンパイル時間 2,604 ms
コンパイル使用メモリ 77,144 KB
実行使用メモリ 57,928 KB
最終ジャッジ日時 2024-04-16 10:26:28
合計ジャッジ時間 22,875 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,065 ms
57,492 KB
testcase_01 AC 148 ms
41,404 KB
testcase_02 AC 252 ms
45,644 KB
testcase_03 AC 1,064 ms
57,928 KB
testcase_04 AC 144 ms
41,300 KB
testcase_05 AC 234 ms
44,976 KB
testcase_06 AC 1,091 ms
57,732 KB
testcase_07 AC 160 ms
41,348 KB
testcase_08 AC 897 ms
52,512 KB
testcase_09 AC 1,332 ms
57,776 KB
testcase_10 AC 149 ms
41,108 KB
testcase_11 AC 805 ms
51,776 KB
testcase_12 AC 1,406 ms
57,808 KB
testcase_13 AC 154 ms
41,496 KB
testcase_14 AC 839 ms
50,288 KB
testcase_15 AC 328 ms
47,792 KB
testcase_16 AC 150 ms
41,196 KB
testcase_17 AC 310 ms
47,012 KB
testcase_18 AC 678 ms
48,272 KB
testcase_19 AC 154 ms
41,524 KB
testcase_20 AC 361 ms
47,804 KB
testcase_21 AC 1,444 ms
57,528 KB
testcase_22 AC 296 ms
46,628 KB
testcase_23 AC 489 ms
47,592 KB
testcase_24 AC 1,335 ms
57,864 KB
testcase_25 AC 152 ms
41,440 KB
testcase_26 AC 345 ms
47,388 KB
testcase_27 AC 145 ms
41,548 KB
testcase_28 AC 141 ms
41,144 KB
testcase_29 AC 142 ms
41,448 KB
testcase_30 AC 139 ms
41,300 KB
testcase_31 AC 142 ms
41,424 KB
testcase_32 AC 140 ms
41,216 KB
testcase_33 AC 144 ms
41,288 KB
testcase_34 AC 147 ms
40,952 KB
testcase_35 AC 153 ms
41,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().solve();
	}
	void solve(){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		DJSet ds=new DJSet(n);
		for(int i=0;i<m;i++){
			int a=sc.nextInt()-1;
			int b=sc.nextInt()-1;
			int c=sc.nextInt();
			ds.setUnion(a, b);
		}
		System.out.println(ds.count());
	}
	class DJSet{
		int n;//the number of vertices
		int[] d;
		DJSet(int n){
			this.n=n;
			d=new int[n];
			Arrays.fill(d, -1);
		}
		int root(int x){
			return d[x]<0?x:root(d[x]);
		}
		boolean setUnion(int x,int y){
			x=root(x);
			y=root(y);
			if(x!=y){
				if(x<y){
					int d=x;
					x=y;
					y=d;
				}
				//x>y
				d[y]+=d[x];
				d[x]=y;
			}
			return x!=y;
		}
		boolean equiv(int x,int y){
			return root(x)==root(y);
		}
		int size(int x){
			return d[root(x)]*(-1);
		}
		//連結グラフの数
		int count(){
			int ct=0;
			for(int u:d){
				if(u<0)ct++;
			}
			return ct;
		}
	}
}
0