結果

問題 No.2712 Play more!
ユーザー 👑 kakel-sankakel-san
提出日時 2024-04-10 00:41:00
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 2,100 bytes
コンパイル時間 7,198 ms
コンパイル使用メモリ 168,704 KB
実行使用メモリ 187,968 KB
最終ジャッジ日時 2024-04-10 00:41:18
合計ジャッジ時間 11,623 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
30,848 KB
testcase_01 AC 56 ms
30,720 KB
testcase_02 AC 56 ms
30,448 KB
testcase_03 AC 55 ms
30,708 KB
testcase_04 AC 54 ms
30,572 KB
testcase_05 AC 55 ms
30,848 KB
testcase_06 AC 54 ms
30,572 KB
testcase_07 AC 108 ms
33,280 KB
testcase_08 AC 113 ms
33,408 KB
testcase_09 AC 116 ms
33,664 KB
testcase_10 AC 54 ms
30,572 KB
testcase_11 AC 85 ms
32,640 KB
testcase_12 AC 148 ms
33,004 KB
testcase_13 AC 86 ms
32,512 KB
testcase_14 AC 120 ms
32,768 KB
testcase_15 AC 209 ms
33,536 KB
testcase_16 AC 66 ms
32,748 KB
testcase_17 AC 59 ms
32,508 KB
testcase_18 AC 70 ms
32,256 KB
testcase_19 AC 61 ms
32,108 KB
testcase_20 AC 93 ms
32,888 KB
testcase_21 AC 72 ms
33,280 KB
testcase_22 AC 151 ms
33,152 KB
testcase_23 AC 65 ms
33,280 KB
testcase_24 AC 79 ms
32,384 KB
testcase_25 AC 65 ms
32,496 KB
testcase_26 AC 73 ms
32,256 KB
testcase_27 AC 102 ms
32,512 KB
testcase_28 AC 88 ms
32,240 KB
testcase_29 AC 72 ms
32,640 KB
testcase_30 AC 163 ms
33,280 KB
testcase_31 AC 126 ms
33,920 KB
testcase_32 AC 116 ms
33,664 KB
testcase_33 AC 56 ms
31,744 KB
testcase_34 AC 55 ms
30,848 KB
testcase_35 AC 53 ms
187,968 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (85 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] - 1);
        }
        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