結果

問題 No.1473 おでぶなおばけさん
ユーザー bluemegane
提出日時 2021-04-11 07:38:21
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,371 bytes
コンパイル時間 2,638 ms
コンパイル使用メモリ 108,272 KB
実行使用メモリ 249,548 KB
最終ジャッジ日時 2024-06-27 03:53:53
合計ジャッジ時間 5,593 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other TLE * 1 -- * 46
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

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