結果

問題 No.100 直列あみだくじ
ユーザー scachescache
提出日時 2014-12-11 23:50:31
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,361 bytes
コンパイル時間 4,356 ms
コンパイル使用メモリ 74,552 KB
実行使用メモリ 58,036 KB
最終ジャッジ日時 2023-09-02 14:10:16
合計ジャッジ時間 11,577 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
53,868 KB
testcase_01 AC 129 ms
55,436 KB
testcase_02 AC 126 ms
55,904 KB
testcase_03 AC 129 ms
55,448 KB
testcase_04 AC 127 ms
55,888 KB
testcase_05 AC 125 ms
55,744 KB
testcase_06 AC 124 ms
55,960 KB
testcase_07 AC 127 ms
55,640 KB
testcase_08 AC 126 ms
55,704 KB
testcase_09 AC 126 ms
55,700 KB
testcase_10 AC 124 ms
55,692 KB
testcase_11 AC 124 ms
55,908 KB
testcase_12 AC 128 ms
55,904 KB
testcase_13 AC 127 ms
55,508 KB
testcase_14 WA -
testcase_15 AC 125 ms
55,580 KB
testcase_16 AC 124 ms
55,732 KB
testcase_17 AC 126 ms
56,012 KB
testcase_18 AC 124 ms
55,712 KB
testcase_19 AC 125 ms
55,780 KB
testcase_20 AC 125 ms
55,812 KB
testcase_21 WA -
testcase_22 AC 125 ms
56,008 KB
testcase_23 AC 124 ms
55,724 KB
testcase_24 AC 123 ms
55,784 KB
testcase_25 AC 123 ms
56,068 KB
testcase_26 AC 124 ms
55,692 KB
testcase_27 AC 126 ms
55,600 KB
testcase_28 AC 126 ms
55,648 KB
testcase_29 AC 127 ms
56,100 KB
testcase_30 AC 130 ms
56,016 KB
testcase_31 AC 123 ms
55,628 KB
testcase_32 AC 130 ms
55,752 KB
testcase_33 WA -
testcase_34 AC 123 ms
55,484 KB
testcase_35 AC 130 ms
55,804 KB
testcase_36 AC 131 ms
55,704 KB
testcase_37 AC 128 ms
55,644 KB
testcase_38 WA -
testcase_39 AC 129 ms
55,540 KB
testcase_40 WA -
testcase_41 AC 132 ms
55,636 KB
testcase_42 AC 131 ms
55,952 KB
testcase_43 WA -
testcase_44 AC 129 ms
55,860 KB
testcase_45 AC 129 ms
55,920 KB
testcase_46 AC 130 ms
55,504 KB
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main0100 {
	public static void main(String[] args) {
		Main0100 p = new Main0100();
	}

	public Main0100() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++)
			a[i] = sc.nextInt()-1;
		solve(n, a);
	}

	public void solve(int n, int[] a) {
		boolean res = true;
		uf(n);
		for(int i=0;i<a.length;i++){
			unite(i, a[i]);
		}
		
		for(int i=0;i<n;i++){
			int c = 1;
			for(int j=0;j<n;j++){
				if(same(i, j))
					c++;
			}
			if(c%2!=0){
				res = false;
				break;
			}
		}
		
		
		System.out.println(res? "Yes" : "No");
	}
	
	
	int[] par;
	int[] rank;
	private void uf(int n){
		par = new int[n];
		rank = new int[n];
		for(int i=0;i<n;i++){
			par[i] = i;
			rank[i] = 0;
		}
	}
	
	// 木の根を返す
	private int find(int x){
		if(par[x] == x)
			return x;
		else
			return par[x] =find(par[x]);
	}
	
	// 併合
	private void unite(int x, int y){
		x = find(x);
		y = find(y);
		
		// すでに同じグループ
		if(x==y)
			return;
		
		if(rank[x]<rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x]==rank[y])
				rank[x]++;
		}
	}
	
	// 同じグループなら真
	private boolean same(int x, int y){
		return find(x) == find(y);
	}

}
0