結果
| 問題 |
No.812 Change of Class
|
| コンテスト | |
| ユーザー |
keymoon
|
| 提出日時 | 2019-04-12 22:03:41 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
MLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,114 bytes |
| コンパイル時間 | 909 ms |
| コンパイル使用メモリ | 115,668 KB |
| 実行使用メモリ | 833,168 KB |
| 最終ジャッジ日時 | 2024-06-12 18:22:23 |
| 合計ジャッジ時間 | 8,318 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 5 MLE * 1 -- * 54 |
コンパイルメッセージ
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;
Stack<Tuple<int, int, int>> stack = new Stack<Tuple<int, int, int>>();
foreach (var neighbour in neighbours[query]) stack.Push(new Tuple<int, int, int>(neighbour, 0, query));
while (stack.Count > 0)
{
var elem = stack.Pop();
var index = elem.Item1;
var depth = elem.Item2;
var came = elem.Item3;
count++;
maxDepth = Max(maxDepth, depth);
foreach (var neighbour in neighbours[index])
{
if (neighbour == came) continue;
stack.Push(new Tuple<int, int, int>(neighbour, depth + 1, index));
}
}
//1→2→4→8→16
int depthLog = 0;
while ((1 << depthLog) <= maxDepth) depthLog++;
Console.WriteLine($"{count} {depthLog}");
}
}
}
keymoon