結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー ngtkanangtkana
提出日時 2020-01-30 11:19:33
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 265 ms / 2,000 ms
コード長 1,218 bytes
コンパイル時間 1,000 ms
コンパイル使用メモリ 65,944 KB
実行使用メモリ 35,640 KB
最終ジャッジ日時 2023-10-14 08:21:31
合計ジャッジ時間 5,069 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
19,624 KB
testcase_01 AC 63 ms
21,604 KB
testcase_02 AC 65 ms
21,672 KB
testcase_03 AC 64 ms
21,600 KB
testcase_04 AC 65 ms
23,656 KB
testcase_05 AC 64 ms
23,600 KB
testcase_06 AC 64 ms
21,648 KB
testcase_07 AC 64 ms
21,528 KB
testcase_08 AC 65 ms
23,648 KB
testcase_09 AC 65 ms
21,644 KB
testcase_10 AC 63 ms
19,572 KB
testcase_11 AC 65 ms
23,636 KB
testcase_12 AC 64 ms
23,688 KB
testcase_13 AC 78 ms
23,568 KB
testcase_14 AC 78 ms
25,636 KB
testcase_15 AC 79 ms
23,692 KB
testcase_16 AC 78 ms
23,640 KB
testcase_17 AC 76 ms
23,564 KB
testcase_18 AC 110 ms
28,336 KB
testcase_19 AC 112 ms
28,620 KB
testcase_20 AC 146 ms
34,260 KB
testcase_21 AC 204 ms
35,008 KB
testcase_22 AC 250 ms
34,960 KB
testcase_23 AC 261 ms
35,640 KB
testcase_24 AC 247 ms
35,504 KB
testcase_25 AC 265 ms
35,556 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];
        var que=new Queue<int>();
        int counter=0;
        for(int i=0;i<n;i++){
            if(ckd[i])continue;
            counter++;
            que.Enqueue(i);
            while(0<que.Count){
                int x=que.Dequeue();
                ckd[x]=true;
                foreach(int y in graph[x]){
                    if(!ckd[y])que.Enqueue(y);
                }
            }
        }
        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