結果

問題 No.2712 Play more!
ユーザー 👑 kakel-sankakel-san
提出日時 2024-04-10 00:40:04
言語 C#
(.NET 8.0.203)
結果
WA  
実行時間 -
コード長 2,096 bytes
コンパイル時間 9,318 ms
コンパイル使用メモリ 168,148 KB
実行使用メモリ 192,436 KB
最終ジャッジ日時 2024-04-10 00:40:24
合計ジャッジ時間 16,890 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
30,848 KB
testcase_01 AC 60 ms
30,976 KB
testcase_02 AC 54 ms
30,580 KB
testcase_03 AC 52 ms
30,720 KB
testcase_04 WA -
testcase_05 AC 53 ms
30,572 KB
testcase_06 AC 58 ms
30,592 KB
testcase_07 AC 110 ms
33,024 KB
testcase_08 AC 115 ms
33,660 KB
testcase_09 AC 117 ms
33,408 KB
testcase_10 WA -
testcase_11 RE -
testcase_12 AC 157 ms
32,768 KB
testcase_13 RE -
testcase_14 WA -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 72 ms
32,256 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 154 ms
33,024 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 71 ms
32,128 KB
testcase_27 WA -
testcase_28 AC 94 ms
32,512 KB
testcase_29 RE -
testcase_30 AC 178 ms
32,768 KB
testcase_31 AC 140 ms
34,304 KB
testcase_32 AC 116 ms
33,792 KB
testcase_33 AC 57 ms
31,616 KB
testcase_34 AC 56 ms
30,976 KB
testcase_35 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (93 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.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[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m) = (c[0], c[1]);
        var a = NList;
        var map = NArr(m);
        WriteLine(Play(n, m, a, map));
    }
    static string Play(int n, int m, int[] a, int[][] map)
    {
        var tree = new List<(int to, long len)>[n];
        for (var i = 0; i < tree.Length; ++i) tree[i] = new List<(int to, long len)>();
        var revtree = new List<int>[n];
        for (var i = 0; i < revtree.Length; ++i) revtree[i] = new List<int>();
        foreach (var edge in map)
        {
            tree[edge[0] - 1].Add((edge[1] - 1, a[edge[1] - 1] - edge[2]));
            revtree[edge[1] - 1].Add(edge[0]);
        }
        var reachable = new bool[n];
        DFS(n - 1, revtree, reachable);
        var INF = long.MinValue / 2;
        var len = Enumerable.Repeat(INF, n).ToArray();
        len[0] = a[0];
        for (var i = 0; i < n; ++i)
        {
            var flg = false;
            for (var j = 0; j < n; ++j) foreach (var next in tree[j])
            {
                if (len[next.to] < len[j] + next.len)
                {
                    if (reachable[next.to]) flg = true;
                    len[next.to] = len[j] + next.len;
                }
            }
            if (i + 1 == n && flg)
            {
                return "inf";
            }
        }
        return len[^1].ToString();
    }
    static void DFS(int cur, List<int>[] tree, bool[] reachable)
    {
        reachable[cur] = true;
        foreach (var next in tree[cur])
        {
            if (reachable[next]) continue;
            DFS(next, tree, reachable);
        }
    }
}
0