結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー 37zigen37zigen
提出日時 2020-01-31 23:07:46
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,031 bytes
コンパイル時間 2,390 ms
コンパイル使用メモリ 77,620 KB
実行使用メモリ 69,288 KB
最終ジャッジ日時 2023-10-17 12:07:18
合計ジャッジ時間 12,228 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
57,456 KB
testcase_01 AC 133 ms
57,448 KB
testcase_02 AC 135 ms
57,568 KB
testcase_03 AC 137 ms
57,424 KB
testcase_04 AC 136 ms
57,420 KB
testcase_05 AC 135 ms
57,480 KB
testcase_06 AC 135 ms
57,624 KB
testcase_07 AC 149 ms
57,660 KB
testcase_08 AC 151 ms
57,420 KB
testcase_09 AC 151 ms
57,724 KB
testcase_10 WA -
testcase_11 AC 151 ms
57,740 KB
testcase_12 AC 154 ms
57,452 KB
testcase_13 AC 318 ms
61,796 KB
testcase_14 AC 328 ms
61,808 KB
testcase_15 AC 321 ms
61,788 KB
testcase_16 AC 316 ms
59,872 KB
testcase_17 AC 324 ms
61,904 KB
testcase_18 AC 463 ms
61,976 KB
testcase_19 WA -
testcase_20 AC 565 ms
62,100 KB
testcase_21 AC 661 ms
66,772 KB
testcase_22 AC 711 ms
68,104 KB
testcase_23 AC 724 ms
69,288 KB
testcase_24 AC 716 ms
68,476 KB
testcase_25 AC 740 ms
68,356 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(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