結果

問題 No.1473 おでぶなおばけさん
ユーザー bluemeganebluemegane
提出日時 2021-04-11 09:50:33
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,356 ms / 2,000 ms
コード長 2,442 bytes
コンパイル時間 1,299 ms
コンパイル使用メモリ 66,000 KB
実行使用メモリ 50,664 KB
最終ジャッジ日時 2023-09-09 12:43:09
合計ジャッジ時間 22,779 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
21,600 KB
testcase_01 AC 66 ms
21,608 KB
testcase_02 AC 778 ms
50,664 KB
testcase_03 AC 498 ms
42,800 KB
testcase_04 AC 507 ms
38,940 KB
testcase_05 AC 179 ms
29,996 KB
testcase_06 AC 779 ms
45,736 KB
testcase_07 AC 884 ms
47,200 KB
testcase_08 AC 1,356 ms
49,240 KB
testcase_09 AC 636 ms
47,292 KB
testcase_10 AC 223 ms
35,436 KB
testcase_11 AC 258 ms
40,444 KB
testcase_12 AC 222 ms
37,100 KB
testcase_13 AC 165 ms
32,680 KB
testcase_14 AC 137 ms
28,304 KB
testcase_15 AC 214 ms
36,560 KB
testcase_16 AC 215 ms
32,760 KB
testcase_17 AC 76 ms
21,776 KB
testcase_18 AC 85 ms
23,700 KB
testcase_19 AC 244 ms
37,972 KB
testcase_20 AC 391 ms
33,788 KB
testcase_21 AC 474 ms
42,584 KB
testcase_22 AC 335 ms
42,020 KB
testcase_23 AC 275 ms
42,620 KB
testcase_24 AC 263 ms
41,600 KB
testcase_25 AC 968 ms
45,872 KB
testcase_26 AC 509 ms
44,092 KB
testcase_27 AC 241 ms
34,420 KB
testcase_28 AC 659 ms
46,932 KB
testcase_29 AC 440 ms
42,944 KB
testcase_30 AC 675 ms
45,408 KB
testcase_31 AC 637 ms
46,932 KB
testcase_32 AC 543 ms
45,736 KB
testcase_33 AC 337 ms
40,912 KB
testcase_34 AC 173 ms
32,728 KB
testcase_35 AC 215 ms
35,412 KB
testcase_36 AC 434 ms
39,888 KB
testcase_37 AC 373 ms
39,080 KB
testcase_38 AC 98 ms
27,124 KB
testcase_39 AC 215 ms
34,848 KB
testcase_40 AC 219 ms
34,724 KB
testcase_41 AC 213 ms
35,204 KB
testcase_42 AC 213 ms
35,240 KB
testcase_43 AC 280 ms
45,948 KB
testcase_44 AC 281 ms
43,812 KB
testcase_45 AC 286 ms
43,808 KB
testcase_46 AC 346 ms
39,016 KB
testcase_47 AC 422 ms
41,744 KB
testcase_48 AC 394 ms
42,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Edge
{
    public int to { get; set; }
    public long d { get; set; }
}

public class P
{
    public int from { get; set; }
    public int step { get; set; }
}

public class Hello
{
    public static int n, step;
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var aa = new List<Edge>[n];
        for (int i = 0; i < n; i++) aa[i] = new List<Edge>();
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var s = int.Parse(line[0]) - 1;
            var t = int.Parse(line[1]) - 1;
            var d = int.Parse(line[2]);
            aa[s].Add(new Edge { to = t, d = d });
            aa[t].Add(new Edge { to = s, d = d });
        }
        getAns(aa);
    }
    static void getAns(List<Edge>[] aa)
    {
        var ok = 1;
        var ng = 1000000001;
        while (ng - ok > 1)
        {
            var mid = ng + (ok - ng) / 2;
            if (check(aa, mid)) ok = mid;
            else ng = mid;
        }
        getSTEP(aa, ok);
        Console.WriteLine("{0} {1}", ok, step);
    }
    static void getSTEP(List<Edge>[] aa, int t)
    {
        step = int.MaxValue;
        var visited = new bool[n];
        var q = new Queue<P>();
        q.Enqueue(new P { from = 0, step = 0 });
        visited[0] = true;
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            if (w.from == n - 1) { step = Min(step, w.step); continue; }
            foreach (var x in aa[w.from])
            {
                if (t <= x.d &&   !visited[x.to]                   )
                {
                    q.Enqueue(new P { from = x.to, step = w.step + 1 });
                    visited[x.to] = true;
                }
            }
        }
    }
    static bool check(List<Edge>[] aa, int t)
    {
        var visited = new bool[n];
        var q = new Queue<int>();
        q.Enqueue(0);
        visited[0] = true;
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            if (w == n - 1) { return true; }
            foreach (var x in aa[w])
            {
                if (t <= x.d && !visited[x.to]) { q.Enqueue(x.to); visited[x.to] = true; }
            }
        }
        return false;
    }
}
0