結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー keymoonkeymoon
提出日時 2020-01-31 21:25:33
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,880 bytes
コンパイル時間 1,397 ms
コンパイル使用メモリ 112,332 KB
実行使用メモリ 29,564 KB
最終ジャッジ日時 2023-10-17 08:38:02
合計ジャッジ時間 3,948 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
25,372 KB
testcase_01 AC 29 ms
25,372 KB
testcase_02 AC 29 ms
25,372 KB
testcase_03 AC 29 ms
25,372 KB
testcase_04 AC 29 ms
25,372 KB
testcase_05 AC 30 ms
25,372 KB
testcase_06 AC 30 ms
25,372 KB
testcase_07 AC 29 ms
25,372 KB
testcase_08 AC 29 ms
25,380 KB
testcase_09 AC 28 ms
25,380 KB
testcase_10 WA -
testcase_11 AC 29 ms
25,372 KB
testcase_12 AC 29 ms
25,372 KB
testcase_13 AC 39 ms
27,428 KB
testcase_14 AC 40 ms
27,428 KB
testcase_15 AC 40 ms
27,428 KB
testcase_16 AC 39 ms
27,428 KB
testcase_17 AC 40 ms
27,428 KB
testcase_18 AC 60 ms
29,476 KB
testcase_19 WA -
testcase_20 AC 78 ms
29,476 KB
testcase_21 AC 109 ms
29,476 KB
testcase_22 AC 133 ms
29,476 KB
testcase_23 AC 139 ms
29,476 KB
testcase_24 AC 136 ms
29,476 KB
testcase_25 AC 137 ms
29,476 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.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        UnionFind uf = new UnionFind(n);
        for (int i = 0; i < n - 1; i++)
        {
            var st = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            uf.TryUnite(st[0], st[1]);
        }
        Console.WriteLine(uf.GroupCount == 1 ? "Bob" : "Alice");
    }
}


class UnionFind
{
    public int Size { get; private set; }
    public int GroupCount { get; private set; }
    public IEnumerable<int> AllRepresents => Parent.Where((x, y) => x == y);
    int[] Sizes;
    int[] Parent;
    public UnionFind(int count)
    {
        Size = count;
        GroupCount = count;
        Parent = new int[count];
        Sizes = new int[count];
        for (int i = 0; i < count; i++) Sizes[Parent[i] = i] = 1;
    }
    public bool TryUnite(int x, int y)
    {
        int xp = Find(x);
        int yp = Find(y);
        if (yp == xp) return false;
        if (Sizes[xp] < Sizes[yp]) { var tmp = xp; xp = yp; yp = tmp; }
        GroupCount--;
        Parent[yp] = xp;
        Sizes[xp] += Sizes[yp];
        return true;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int GetSize(int x) => Sizes[Find(x)];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int Find(int x)
    {
        while (x != Parent[x]) x = (Parent[x] = Parent[Parent[x]]);
        return x;
    }
}
0