結果

問題 No.977 アリス仕掛けの摩天楼
コンテスト
ユーザー ngtkana
提出日時 2020-01-30 11:18:52
言語 C#(csc)
(csc 3.9.0)
コンパイル:
csc -langversion:latest -unsafe -warn:0 -o+ /r:System.Numerics.dll _filename_ -out:a.exe
実行:
/usr/bin/mono a.exe
結果
WA  
実行時間 -
コード長 1,195 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 736 ms
コンパイル使用メモリ 108,416 KB
実行使用メモリ 33,524 KB
最終ジャッジ日時 2026-04-05 07:41:23
合計ジャッジ時間 2,856 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #
raw source code

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;
            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