結果

問題 No.100 直列あみだくじ
ユーザー scachescache
提出日時 2014-12-12 00:23:17
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,508 bytes
コンパイル時間 3,126 ms
コンパイル使用メモリ 74,164 KB
実行使用メモリ 56,484 KB
最終ジャッジ日時 2023-09-02 14:14:14
合計ジャッジ時間 11,020 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,940 KB
testcase_01 AC 124 ms
56,040 KB
testcase_02 AC 123 ms
56,068 KB
testcase_03 AC 127 ms
55,872 KB
testcase_04 AC 127 ms
55,884 KB
testcase_05 AC 120 ms
55,720 KB
testcase_06 AC 123 ms
55,816 KB
testcase_07 AC 121 ms
55,748 KB
testcase_08 AC 123 ms
55,876 KB
testcase_09 AC 124 ms
56,480 KB
testcase_10 AC 123 ms
56,100 KB
testcase_11 AC 121 ms
55,676 KB
testcase_12 AC 122 ms
56,012 KB
testcase_13 AC 124 ms
55,908 KB
testcase_14 WA -
testcase_15 AC 125 ms
56,016 KB
testcase_16 AC 123 ms
55,824 KB
testcase_17 AC 127 ms
56,032 KB
testcase_18 AC 125 ms
56,392 KB
testcase_19 AC 121 ms
55,676 KB
testcase_20 AC 122 ms
56,440 KB
testcase_21 WA -
testcase_22 AC 122 ms
56,172 KB
testcase_23 AC 123 ms
55,748 KB
testcase_24 AC 123 ms
56,004 KB
testcase_25 AC 124 ms
55,800 KB
testcase_26 AC 123 ms
55,728 KB
testcase_27 AC 123 ms
55,776 KB
testcase_28 AC 125 ms
56,484 KB
testcase_29 AC 122 ms
55,928 KB
testcase_30 AC 129 ms
55,712 KB
testcase_31 AC 123 ms
55,572 KB
testcase_32 AC 129 ms
55,956 KB
testcase_33 WA -
testcase_34 AC 123 ms
55,964 KB
testcase_35 AC 129 ms
55,728 KB
testcase_36 AC 129 ms
56,040 KB
testcase_37 AC 127 ms
55,836 KB
testcase_38 WA -
testcase_39 AC 129 ms
55,520 KB
testcase_40 WA -
testcase_41 AC 128 ms
56,116 KB
testcase_42 AC 129 ms
55,980 KB
testcase_43 WA -
testcase_44 AC 126 ms
56,360 KB
testcase_45 AC 128 ms
56,044 KB
testcase_46 AC 127 ms
56,108 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]);
		}
		
		int gc = 0;
		boolean[] isVisit = new boolean[n];
		for(int i=0;i<n;i++){
			if(isVisit[i])
				continue;
			
			int c = 0;
			isVisit[i] = true;
			for(int j=0;j<n;j++){
				if(same(i, j)){
					isVisit[j] = true;
					c++;
				}
			}
			if(c%2==0){
				gc++;
				break;
			}
		}
		
		
		System.out.println(gc%2==0 ? "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