結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
57,488 KB
testcase_01 AC 132 ms
57,564 KB
testcase_02 AC 129 ms
57,452 KB
testcase_03 AC 132 ms
57,536 KB
testcase_04 AC 132 ms
57,596 KB
testcase_05 AC 134 ms
57,528 KB
testcase_06 AC 134 ms
55,704 KB
testcase_07 AC 150 ms
57,780 KB
testcase_08 AC 150 ms
57,504 KB
testcase_09 AC 147 ms
57,376 KB
testcase_10 WA -
testcase_11 AC 150 ms
57,876 KB
testcase_12 AC 148 ms
57,844 KB
testcase_13 AC 316 ms
61,872 KB
testcase_14 AC 332 ms
61,980 KB
testcase_15 AC 308 ms
61,752 KB
testcase_16 AC 332 ms
61,836 KB
testcase_17 AC 315 ms
61,976 KB
testcase_18 AC 461 ms
62,100 KB
testcase_19 WA -
testcase_20 AC 558 ms
62,232 KB
testcase_21 AC 658 ms
66,672 KB
testcase_22 AC 725 ms
69,396 KB
testcase_23 AC 724 ms
70,548 KB
testcase_24 AC 727 ms
70,484 KB
testcase_25 AC 762 ms
68,408 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){
			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