結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー tomomo2b2tomomo2b2
提出日時 2020-01-31 21:55:16
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,590 bytes
コンパイル時間 3,861 ms
コンパイル使用メモリ 111,740 KB
実行使用メモリ 58,024 KB
最終ジャッジ日時 2023-10-17 09:34:29
合計ジャッジ時間 7,118 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
26,492 KB
testcase_01 AC 29 ms
26,492 KB
testcase_02 AC 28 ms
26,492 KB
testcase_03 AC 28 ms
26,508 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 27 ms
26,508 KB
testcase_07 AC 26 ms
26,512 KB
testcase_08 AC 27 ms
26,512 KB
testcase_09 AC 28 ms
26,512 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 43 ms
32,056 KB
testcase_15 AC 44 ms
32,056 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 119 ms
42,444 KB
testcase_21 AC 204 ms
49,996 KB
testcase_22 AC 278 ms
55,092 KB
testcase_23 AC 330 ms
58,024 KB
testcase_24 WA -
testcase_25 AC 318 ms
58,012 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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();
    }
}
0