結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| ユーザー |
ngtkana
|
| 提出日時 | 2020-01-30 11:01:53 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 189 ms / 2,000 ms |
| コード長 | 1,142 bytes |
| コンパイル時間 | 2,300 ms |
| コンパイル使用メモリ | 108,032 KB |
| 実行使用メモリ | 32,632 KB |
| 最終ジャッジ日時 | 2024-09-16 03:27:39 |
| 合計ジャッジ時間 | 4,372 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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];
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");
}
}
ngtkana