結果
問題 |
No.977 アリス仕掛けの摩天楼
|
ユーザー |
![]() |
提出日時 | 2020-01-30 11:19:33 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 245 ms / 2,000 ms |
コード長 | 1,218 bytes |
コンパイル時間 | 949 ms |
コンパイル使用メモリ | 114,580 KB |
実行使用メモリ | 32,768 KB |
最終ジャッジ日時 | 2024-09-16 03:28:16 |
合計ジャッジ時間 | 3,975 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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"); } }