結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー 37zigen37zigen
提出日時 2020-01-31 23:05:14
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,089 bytes
コンパイル時間 3,072 ms
コンパイル使用メモリ 77,800 KB
実行使用メモリ 61,780 KB
最終ジャッジ日時 2023-10-17 12:00:58
合計ジャッジ時間 11,273 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
57,608 KB
testcase_01 AC 125 ms
57,448 KB
testcase_02 AC 129 ms
57,476 KB
testcase_03 AC 127 ms
57,516 KB
testcase_04 AC 128 ms
57,504 KB
testcase_05 AC 128 ms
57,552 KB
testcase_06 AC 128 ms
57,396 KB
testcase_07 AC 146 ms
57,784 KB
testcase_08 AC 141 ms
57,276 KB
testcase_09 AC 139 ms
57,772 KB
testcase_10 WA -
testcase_11 AC 137 ms
57,508 KB
testcase_12 AC 139 ms
57,548 KB
testcase_13 AC 309 ms
61,780 KB
testcase_14 AC 312 ms
47,236 KB
testcase_15 AC 301 ms
47,308 KB
testcase_16 AC 307 ms
46,284 KB
testcase_17 AC 304 ms
47,480 KB
testcase_18 AC 430 ms
47,612 KB
testcase_19 WA -
testcase_20 AC 512 ms
48,064 KB
testcase_21 AC 605 ms
52,224 KB
testcase_22 AC 646 ms
53,516 KB
testcase_23 AC 679 ms
55,588 KB
testcase_24 AC 656 ms
56,320 KB
testcase_25 AC 719 ms
53,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;
import java.io.*;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	class DJSet{
		int n;
		int[] upper;
		
		public DJSet(int n){
			this.n=n;
			upper=new int[n];
			Arrays.fill(upper,-1);
		}
		
		boolean equiv(int a,int b){
			return root(a)==root(b);
		}
		
		int root(int x){
			return upper[x]<0?x:(upper[x]=root(upper[x]));
		}
		
		void setUnion(int a,int b){
			a=root(a);
			b=root(b);
			if(upper[a]>0||upper[b]>0)throw new AssertionError();
			if(a==b)return;
			if(upper[a]<upper[b]){setUnion(b,a);return;}
			upper[b]+=upper[a];
			upper[a]=b;
		}
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int N=sc.nextInt();
		DJSet ds=new DJSet(N);
		for(int i=0;i<N-1;++i){
			int u=sc.nextInt();
			int v=sc.nextInt();
			ds.setUnion(u,v);
		}
		int ans=0;
		for(int i=0;i<N;++i){
			if(ds.upper[i]<0)++ans;
		}

		pw.println(ans==1?"Bob":"Alice");
		pw.close();
	}
	
	void tr(Object...o){System.out.println(Arrays.deepToString(o));}
}



0