結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー 37zigen37zigen
提出日時 2020-01-31 23:23:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 767 ms / 2,000 ms
コード長 1,242 bytes
コンパイル時間 2,227 ms
コンパイル使用メモリ 78,144 KB
実行使用メモリ 70,560 KB
最終ジャッジ日時 2023-10-17 12:37:50
合計ジャッジ時間 12,830 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
55,408 KB
testcase_01 AC 136 ms
57,452 KB
testcase_02 AC 132 ms
57,544 KB
testcase_03 AC 134 ms
57,512 KB
testcase_04 AC 133 ms
57,456 KB
testcase_05 AC 137 ms
57,496 KB
testcase_06 AC 135 ms
57,556 KB
testcase_07 AC 148 ms
57,680 KB
testcase_08 AC 155 ms
57,592 KB
testcase_09 AC 152 ms
57,596 KB
testcase_10 AC 153 ms
57,740 KB
testcase_11 AC 151 ms
57,468 KB
testcase_12 AC 152 ms
57,660 KB
testcase_13 AC 325 ms
61,768 KB
testcase_14 AC 327 ms
61,808 KB
testcase_15 AC 310 ms
61,632 KB
testcase_16 AC 315 ms
61,744 KB
testcase_17 AC 335 ms
61,832 KB
testcase_18 AC 480 ms
62,056 KB
testcase_19 AC 464 ms
62,080 KB
testcase_20 AC 531 ms
60,300 KB
testcase_21 AC 673 ms
66,808 KB
testcase_22 AC 724 ms
69,272 KB
testcase_23 AC 743 ms
70,560 KB
testcase_24 AC 736 ms
69,528 KB
testcase_25 AC 767 ms
68,448 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;
		}
		
		int sz(int a){
			return -upper[root(a)];
		}
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int N=sc.nextInt();
		DJSet ds=new DJSet(N);
		int[] deg=new int[N];
		for(int i=0;i<N-1;++i){
			int u=sc.nextInt();
			int v=sc.nextInt();
			deg[u]++;
			deg[v]++;
			ds.setUnion(u,v);
		}
		int sz=0;
		for(int i=0;i<N;++i){
			if(ds.upper[i]<0)++sz;
		}
		boolean Bob=sz==1;
		if(sz==2){
			Bob=true;
			for(int i=0;i<N;++i){
				Bob&=deg[i]==2||deg[i]==0;
			}
		}
		
		pw.println(Bob?"Bob":"Alice");
		pw.close();
	}
	
	void tr(Object...o){System.out.println(Arrays.deepToString(o));}
}



0