結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
57,460 KB
testcase_01 AC 134 ms
57,496 KB
testcase_02 AC 134 ms
57,468 KB
testcase_03 AC 134 ms
57,604 KB
testcase_04 AC 135 ms
57,516 KB
testcase_05 AC 134 ms
57,108 KB
testcase_06 AC 136 ms
57,644 KB
testcase_07 AC 149 ms
57,676 KB
testcase_08 AC 150 ms
57,628 KB
testcase_09 AC 153 ms
57,712 KB
testcase_10 WA -
testcase_11 AC 152 ms
57,712 KB
testcase_12 AC 164 ms
57,764 KB
testcase_13 AC 319 ms
61,928 KB
testcase_14 AC 334 ms
61,740 KB
testcase_15 AC 323 ms
62,064 KB
testcase_16 AC 314 ms
61,800 KB
testcase_17 AC 333 ms
61,736 KB
testcase_18 AC 469 ms
62,144 KB
testcase_19 WA -
testcase_20 AC 572 ms
62,468 KB
testcase_21 AC 675 ms
66,896 KB
testcase_22 AC 730 ms
68,204 KB
testcase_23 AC 739 ms
70,460 KB
testcase_24 AC 741 ms
70,408 KB
testcase_25 AC 762 ms
68,404 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&=(ds.sz(i)==2&&deg[i]==2)||ds.sz(i)==1;
			}
		}
		
		pw.println(Bob?"Bob":"Alice");
		pw.close();
	}
	
	void tr(Object...o){System.out.println(Arrays.deepToString(o));}
}



0