結果

問題 No.1565 Union
ユーザー 👑 kakel-sankakel-san
提出日時 2024-03-14 23:16:19
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 325 ms / 2,000 ms
コード長 1,412 bytes
コンパイル時間 14,090 ms
コンパイル使用メモリ 170,104 KB
実行使用メモリ 221,028 KB
最終ジャッジ日時 2024-05-18 03:40:09
合計ジャッジ時間 21,628 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
30,836 KB
testcase_01 AC 50 ms
30,592 KB
testcase_02 AC 50 ms
30,720 KB
testcase_03 AC 50 ms
30,720 KB
testcase_04 AC 50 ms
30,592 KB
testcase_05 AC 52 ms
30,840 KB
testcase_06 AC 55 ms
30,716 KB
testcase_07 AC 51 ms
30,720 KB
testcase_08 AC 52 ms
30,836 KB
testcase_09 AC 56 ms
30,592 KB
testcase_10 AC 165 ms
58,892 KB
testcase_11 AC 176 ms
61,248 KB
testcase_12 AC 216 ms
63,888 KB
testcase_13 AC 91 ms
45,808 KB
testcase_14 AC 247 ms
64,572 KB
testcase_15 AC 313 ms
64,356 KB
testcase_16 AC 272 ms
64,484 KB
testcase_17 AC 325 ms
64,488 KB
testcase_18 AC 302 ms
64,432 KB
testcase_19 AC 290 ms
64,360 KB
testcase_20 AC 237 ms
64,468 KB
testcase_21 AC 237 ms
64,584 KB
testcase_22 AC 241 ms
64,584 KB
testcase_23 AC 231 ms
64,560 KB
testcase_24 AC 243 ms
64,580 KB
testcase_25 AC 257 ms
64,464 KB
testcase_26 AC 245 ms
64,600 KB
testcase_27 AC 241 ms
64,468 KB
testcase_28 AC 253 ms
64,452 KB
testcase_29 AC 251 ms
221,028 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (132 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray();
    static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m) = (c[0], c[1]);
        var map = NMap(m);
        var tree = new List<int>[n];
        for (var i = 0; i < tree.Length; ++i) tree[i] = new List<int>();
        foreach (var edge in map)
        {
            tree[edge[0]].Add(edge[1]);
            tree[edge[1]].Add(edge[0]);
        }
        var INF = int.MaxValue / 2;
        var len = Enumerable.Repeat(INF, n).ToArray();
        len[0] = 0;
        var q = new Queue<(int pos, int len)>();
        q.Enqueue((0, 0));
        while (q.Count > 0)
        {
            var cur = q.Dequeue();
            foreach (var next in tree[cur.pos])
            {
                if (len[next] <= cur.len + 1) continue;
                len[next] = cur.len + 1;
                q.Enqueue((next, len[next]));
            }
        }
        WriteLine(len[^1] == INF ? -1 : len[^1]);
    }
}
 
0