結果

問題 No.994 ばらばらコイン
ユーザー g4np0n_kyoprog4np0n_kyopro
提出日時 2020-02-21 21:41:46
言語 C#(csc)
(csc 3.9.0)
結果
MLE  
実行時間 -
コード長 3,827 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 116,928 KB
実行使用メモリ 823,756 KB
最終ジャッジ日時 2024-04-17 07:31:15
合計ジャッジ時間 3,205 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
19,328 KB
testcase_01 AC 31 ms
19,456 KB
testcase_02 MLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            //

            int N;int K;
            Multi(out N, out K);
            int[][] Edge = new int[N][];
            for(int i = 0; i < N; i++)
            {
                Edge[i] = Enumerable.Repeat(0, N).ToArray();
            }

            for(int i = 0; i < N - 1; i++)
            {
                var cin = GetIntArray().Select(s => s - 1).ToArray();
                Edge[cin[0]][cin[1]] = 1;
                Edge[cin[1]][cin[0]] = 1;
            }

            int[] dist = Enumerable.Repeat(-1, N).ToArray();
            var que = new Queue<int>();
            que.Enqueue(0);
            dist[0] = 0;
            while (que.Count > 0)
            {
                var n = que.Dequeue();
                for(int i = 0; i < N; i++)
                {
                    if(Edge[n][i]==1 && dist[i] == -1)
                    {
                        dist[i] = dist[n] + 1;
                        que.Enqueue(i);
                    }
                }
            }

            int ans;
            if (dist.Count(d => d != -1) >= K)
            {
                ans = K - 1;
            }
            else
            {
                ans = -1;
            }

            Console.WriteLine(ans);

            //
            Console.Out.Flush();
            Console.ReadKey();
        }


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c, out V d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<V>(ar[3]);
        }
    }
}
0