結果
問題 | No.812 Change of Class |
ユーザー |
![]() |
提出日時 | 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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 60 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
//#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}"); } } }