結果

問題 No.1473 おでぶなおばけさん
ユーザー bluemeganebluemegane
提出日時 2021-04-11 09:47:13
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,442 bytes
コンパイル時間 1,741 ms
コンパイル使用メモリ 68,180 KB
実行使用メモリ 48,636 KB
最終ジャッジ日時 2023-09-09 12:39:52
合計ジャッジ時間 19,629 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
21,760 KB
testcase_01 AC 62 ms
19,676 KB
testcase_02 AC 551 ms
48,636 KB
testcase_03 AC 346 ms
42,732 KB
testcase_04 AC 316 ms
38,904 KB
testcase_05 AC 159 ms
27,988 KB
testcase_06 AC 518 ms
41,792 KB
testcase_07 AC 597 ms
47,104 KB
testcase_08 AC 959 ms
47,328 KB
testcase_09 AC 478 ms
47,268 KB
testcase_10 AC 208 ms
33,288 KB
testcase_11 AC 235 ms
36,380 KB
testcase_12 AC 205 ms
38,964 KB
testcase_13 AC 157 ms
34,872 KB
testcase_14 AC 133 ms
28,336 KB
testcase_15 AC 203 ms
36,388 KB
testcase_16 AC 202 ms
34,808 KB
testcase_17 AC 73 ms
23,656 KB
testcase_18 AC 83 ms
21,776 KB
testcase_19 AC 204 ms
35,508 KB
testcase_20 AC 281 ms
41,628 KB
testcase_21 AC 347 ms
42,700 KB
testcase_22 AC 290 ms
45,804 KB
testcase_23 AC 239 ms
42,668 KB
testcase_24 AC 236 ms
39,684 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 433 ms
44,964 KB
testcase_29 AC 304 ms
42,732 KB
testcase_30 AC 433 ms
45,448 KB
testcase_31 AC 430 ms
44,768 KB
testcase_32 AC 366 ms
45,664 KB
testcase_33 AC 260 ms
42,704 KB
testcase_34 AC 144 ms
32,728 KB
testcase_35 AC 179 ms
35,284 KB
testcase_36 AC 304 ms
37,852 KB
testcase_37 AC 273 ms
43,176 KB
testcase_38 AC 92 ms
29,108 KB
testcase_39 AC 200 ms
36,864 KB
testcase_40 AC 203 ms
34,924 KB
testcase_41 AC 200 ms
35,348 KB
testcase_42 AC 201 ms
35,280 KB
testcase_43 AC 258 ms
43,932 KB
testcase_44 AC 256 ms
45,768 KB
testcase_45 AC 256 ms
46,104 KB
testcase_46 AC 271 ms
41,116 KB
testcase_47 AC 327 ms
43,556 KB
testcase_48 AC 320 ms
42,432 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 = 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 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