結果

問題 No.1565 Union
ユーザー 👑 kakel-sankakel-san
提出日時 2024-03-14 23:16:19
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 436 ms / 2,000 ms
コード長 1,412 bytes
コンパイル時間 15,889 ms
コンパイル使用メモリ 157,888 KB
実行使用メモリ 213,576 KB
最終ジャッジ日時 2024-03-14 23:16:47
合計ジャッジ時間 17,435 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
33,060 KB
testcase_01 AC 83 ms
33,060 KB
testcase_02 AC 84 ms
33,060 KB
testcase_03 AC 83 ms
33,060 KB
testcase_04 AC 83 ms
33,060 KB
testcase_05 AC 82 ms
33,060 KB
testcase_06 AC 86 ms
33,060 KB
testcase_07 AC 83 ms
33,060 KB
testcase_08 AC 83 ms
33,060 KB
testcase_09 AC 84 ms
33,060 KB
testcase_10 AC 194 ms
61,248 KB
testcase_11 AC 233 ms
63,596 KB
testcase_12 AC 288 ms
66,368 KB
testcase_13 AC 129 ms
48,164 KB
testcase_14 AC 295 ms
66,908 KB
testcase_15 AC 406 ms
66,828 KB
testcase_16 AC 359 ms
66,828 KB
testcase_17 AC 436 ms
66,832 KB
testcase_18 AC 419 ms
66,956 KB
testcase_19 AC 414 ms
66,956 KB
testcase_20 AC 301 ms
67,064 KB
testcase_21 AC 299 ms
67,064 KB
testcase_22 AC 307 ms
67,064 KB
testcase_23 AC 332 ms
66,936 KB
testcase_24 AC 303 ms
66,936 KB
testcase_25 AC 315 ms
66,936 KB
testcase_26 AC 310 ms
66,936 KB
testcase_27 AC 335 ms
66,936 KB
testcase_28 AC 309 ms
66,936 KB
testcase_29 AC 311 ms
213,576 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (119 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.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