結果

問題 No.1473 おでぶなおばけさん
ユーザー bluemeganebluemegane
提出日時 2021-04-11 07:38:21
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,371 bytes
コンパイル時間 1,009 ms
コンパイル使用メモリ 68,360 KB
実行使用メモリ 15,516 KB
最終ジャッジ日時 2023-09-09 10:45:16
合計ジャッジ時間 7,535 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
15,516 KB
testcase_01 AC 63 ms
15,404 KB
testcase_02 TLE -
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 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます

ソースコード

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 = 0;
        var ng = 1000000000;
        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 minstep = new int[n];
        for (int i = 0; i < n; i++) minstep[i] = int.MaxValue;
        var q = new Queue<P>();
        q.Enqueue(new P { from = 0, step = 0 });
        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 && (w.step + 1 <= minstep[x.to]))
                {
                    q.Enqueue(new P { from = x.to, step = w.step + 1 });
                    minstep[x.to] = w.step + 1;
                }
            }
        }
    }
    static bool check(List<Edge>[] aa, int t)
    {
        var q = new Queue<int>();
        q.Enqueue(0);
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            if (w == n - 1) { return true; }
            foreach (var x in aa[w])
            {
                if (t <= x.d) q.Enqueue(x.to);
            }
        }
        return false;
    }
}
0