結果

問題 No.812 Change of Class
ユーザー keymoonkeymoon
提出日時 2019-04-12 22:09:38
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 905 ms / 4,000 ms
コード長 2,244 bytes
コンパイル時間 870 ms
コンパイル使用メモリ 117,504 KB
実行使用メモリ 63,140 KB
最終ジャッジ日時 2024-06-12 18:29:49
合計ジャッジ時間 23,097 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 521 ms
55,336 KB
testcase_01 AC 102 ms
48,332 KB
testcase_02 AC 293 ms
53,508 KB
testcase_03 AC 606 ms
60,964 KB
testcase_04 AC 533 ms
58,004 KB
testcase_05 AC 905 ms
57,472 KB
testcase_06 AC 750 ms
60,188 KB
testcase_07 AC 32 ms
28,244 KB
testcase_08 AC 30 ms
28,220 KB
testcase_09 AC 800 ms
60,372 KB
testcase_10 AC 822 ms
60,492 KB
testcase_11 AC 60 ms
38,392 KB
testcase_12 AC 470 ms
59,036 KB
testcase_13 AC 29 ms
26,432 KB
testcase_14 AC 28 ms
26,592 KB
testcase_15 AC 553 ms
57,084 KB
testcase_16 AC 59 ms
33,440 KB
testcase_17 AC 506 ms
55,528 KB
testcase_18 AC 375 ms
52,004 KB
testcase_19 AC 427 ms
56,520 KB
testcase_20 AC 835 ms
59,728 KB
testcase_21 AC 373 ms
54,280 KB
testcase_22 AC 180 ms
47,412 KB
testcase_23 AC 52 ms
30,464 KB
testcase_24 AC 70 ms
39,276 KB
testcase_25 AC 145 ms
47,364 KB
testcase_26 AC 668 ms
58,824 KB
testcase_27 AC 599 ms
57,744 KB
testcase_28 AC 419 ms
56,592 KB
testcase_29 AC 122 ms
49,488 KB
testcase_30 AC 526 ms
59,956 KB
testcase_31 AC 486 ms
57,644 KB
testcase_32 AC 216 ms
51,432 KB
testcase_33 AC 542 ms
57,360 KB
testcase_34 AC 65 ms
36,212 KB
testcase_35 AC 118 ms
43,008 KB
testcase_36 AC 72 ms
37,852 KB
testcase_37 AC 277 ms
53,648 KB
testcase_38 AC 35 ms
30,436 KB
testcase_39 AC 289 ms
56,188 KB
testcase_40 AC 92 ms
45,164 KB
testcase_41 AC 33 ms
30,300 KB
testcase_42 AC 581 ms
53,808 KB
testcase_43 AC 96 ms
42,296 KB
testcase_44 AC 432 ms
55,620 KB
testcase_45 AC 73 ms
37,724 KB
testcase_46 AC 86 ms
39,608 KB
testcase_47 AC 425 ms
53,820 KB
testcase_48 AC 418 ms
57,124 KB
testcase_49 AC 144 ms
46,828 KB
testcase_50 AC 35 ms
26,332 KB
testcase_51 AC 121 ms
44,200 KB
testcase_52 AC 202 ms
47,416 KB
testcase_53 AC 109 ms
46,688 KB
testcase_54 AC 100 ms
48,300 KB
testcase_55 AC 457 ms
61,000 KB
testcase_56 AC 624 ms
61,152 KB
testcase_57 AC 649 ms
61,716 KB
testcase_58 AC 346 ms
55,100 KB
testcase_59 AC 732 ms
63,140 KB
testcase_60 AC 30 ms
26,484 KB
testcase_61 AC 30 ms
26,564 KB
testcase_62 AC 31 ms
26,544 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

//#define topt
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


class P
{
    static void Main()
    {
        int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        List<int>[] neighbours = Enumerable.Repeat(0, nm[0]).Select(_ => new List<int>()).ToArray();
        for (int i = 0; i < nm[1]; i++)
        {
            int[] ab = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
            neighbours[ab[0]].Add(ab[1]);
            neighbours[ab[1]].Add(ab[0]);
        }
        int q = int.Parse(Console.ReadLine());
        for (int i = 0; i < q; i++)
        {
            int query = int.Parse(Console.ReadLine()) - 1;

            var maxDepth = 0;
            var count = 0;

            HashSet<int> arrived = new HashSet<int>();
            arrived.Add(query);

            Queue<Tuple<int, int>> stack = new Queue<Tuple<int, int>>();
            foreach (var neighbour in neighbours[query])
            {
                arrived.Add(neighbour);
                stack.Enqueue(new Tuple<int, int>(neighbour, 0));
            }
            while (stack.Count > 0)
            {
                var elem = stack.Dequeue();
                var index = elem.Item1;
                var depth = elem.Item2;
                count++;
                maxDepth = Max(maxDepth, depth);
                foreach (var neighbour in neighbours[index])
                {
                    if (arrived.Contains(neighbour)) continue;
                    arrived.Add(neighbour);
                    stack.Enqueue(new Tuple<int, int>(neighbour, depth + 1));
                }
            }
            int depthLog = 0;
            while ((1 << depthLog) <= maxDepth) depthLog++;

            Console.WriteLine($"{count} {depthLog}");
        }
    }
}
0