結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー ngtkanangtkana
提出日時 2020-01-30 11:01:53
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,142 bytes
コンパイル時間 1,382 ms
コンパイル使用メモリ 64,072 KB
実行使用メモリ 37,644 KB
最終ジャッジ日時 2023-10-14 08:20:50
合計ジャッジ時間 4,988 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
21,772 KB
testcase_01 AC 54 ms
21,684 KB
testcase_02 AC 55 ms
21,476 KB
testcase_03 AC 57 ms
21,568 KB
testcase_04 AC 56 ms
21,824 KB
testcase_05 AC 54 ms
21,680 KB
testcase_06 AC 54 ms
19,536 KB
testcase_07 AC 55 ms
21,676 KB
testcase_08 AC 53 ms
21,628 KB
testcase_09 AC 60 ms
23,736 KB
testcase_10 AC 59 ms
23,592 KB
testcase_11 AC 56 ms
21,752 KB
testcase_12 AC 56 ms
21,628 KB
testcase_13 AC 63 ms
23,724 KB
testcase_14 AC 66 ms
25,964 KB
testcase_15 AC 64 ms
26,076 KB
testcase_16 AC 66 ms
25,716 KB
testcase_17 AC 67 ms
24,860 KB
testcase_18 AC 92 ms
28,456 KB
testcase_19 AC 98 ms
29,792 KB
testcase_20 AC 122 ms
31,504 KB
testcase_21 AC 158 ms
32,980 KB
testcase_22 AC 187 ms
34,956 KB
testcase_23 AC 202 ms
33,548 KB
testcase_24 AC 197 ms
35,700 KB
testcase_25 AC 197 ms
37,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Linq;
using System.Collections.Generic;

public static class Program{
    public static void Main() {
        int n=int.Parse(Console.ReadLine());
        var graph=Enumerable.Range(0,n)
            .Select(_=>new List<int>()).ToArray();
        for(int i=0;i<n-1;i++){
            int[]uv=Console.ReadLine().Split().Select(int.Parse).ToArray();
            graph[uv[0]].Add(uv[1]);
            graph[uv[1]].Add(uv[0]);
        }

        bool[]ckd=new bool[n];
        Action<int>dfs=null;
        dfs=x=>{
            ckd[x]=true;
            foreach(int y in graph[x]){
                if(!ckd[y])dfs(y);
            }
        };
        int counter=0;
        for(int i=0;i<n;i++){
            if(!ckd[i]){
                counter++;
                dfs(i);
            }
        }
        if(counter!=2) {
            Console.WriteLine(counter==1?"Bob":"Alice");
            return;
        }
        for(int i=0;i<n;i++){
            if(graph[i].Count!=0&&graph[i].Count!=2){
                Console.WriteLine("Alice");
                return;
            }
        }
        Console.WriteLine("Bob");
    }
}
0