結果
| 問題 | No.977 アリス仕掛けの摩天楼 |
| コンテスト | |
| ユーザー |
tomomo2b2
|
| 提出日時 | 2020-01-31 21:55:16 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,590 bytes |
| コンパイル時間 | 2,638 ms |
| コンパイル使用メモリ | 110,752 KB |
| 実行使用メモリ | 59,744 KB |
| 最終ジャッジ日時 | 2024-09-17 08:02:20 |
| 合計ジャッジ時間 | 4,787 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 WA * 11 |
コンパイルメッセージ
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;
using System.Text;
using System.Numerics;
class Node<T>
{
private int Height { get; set; }
private Node<T> Parent { get; set; }
private long size;
public long Size { get { return Find().size; } set { size = value; } }
public T Item { get; }
public Node(T item)
{
Height = 0;
Parent = this;
Item = item;
Size = 1;
}
public Node<T> Find()
{
if (Parent == this)
{
return this;
}
var p = Parent.Find();
Parent = p;
return p;
}
public static void Unite(Node<T> a, Node<T> b)
{
var p = a.Find();
var q = b.Find();
if (p.Height < q.Height)
{
p.Parent = q;
q.Height = Math.Max(p.Height + 1, q.Height);
q.Size += p.Size;
p.Size = 0;
}
else
{
q.Parent = p;
p.Height = Math.Max(q.Height + 1, p.Height);
p.Size += q.Size;
q.Size = 0;
}
}
}
class MyClass
{
public static void Solve()
{
var N = int.Parse(Console.ReadLine());
var adj = new HashSet<int>[N];
var uf = new Node<int>[N];
for (int i = 0; i < N; i++)
{
adj[i] = new HashSet<int>();
uf[i] = new Node<int>(i);
}
for (int i = 0; i < N-1; i++)
{
var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
var u = input[0];
var v = input[1];
adj[u].Add(v);
adj[v].Add(u);
Node<int>.Unite(uf[u], uf[v]);
}
var set = new HashSet<int>();
for (int i = 0; i < N; i++)
{
set.Add(uf[i].Find().Item);
}
var comp = set.Count;
var sol = 0;
var deg1 = 0;
for (int i = 0; i < N; i++)
{
if (adj[i].Count == 0)
{
sol++;
}
else if (adj[i].Count == 1)
{
deg1++;
}
}
if (sol >= 2 || comp >= 3)
{
Console.WriteLine("Alice");
}
else if (comp == 1)
{
Console.WriteLine("Bob");
}
else
{
}
}
public static void Main()
{
var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
Console.SetOut(sw);
Solve();
Console.Out.Flush();
}
}
tomomo2b2