結果

問題 No.2712 Play more!
ユーザー tentententen
提出日時 2024-04-01 18:24:18
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,650 bytes
コンパイル時間 2,538 ms
コンパイル使用メモリ 80,356 KB
実行使用メモリ 58,792 KB
最終ジャッジ日時 2024-04-01 18:24:28
合計ジャッジ時間 7,631 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
54,116 KB
testcase_01 AC 53 ms
54,108 KB
testcase_02 AC 53 ms
54,116 KB
testcase_03 AC 54 ms
54,124 KB
testcase_04 AC 54 ms
54,108 KB
testcase_05 AC 53 ms
54,124 KB
testcase_06 AC 54 ms
54,108 KB
testcase_07 AC 129 ms
56,416 KB
testcase_08 AC 132 ms
56,172 KB
testcase_09 AC 135 ms
56,132 KB
testcase_10 AC 54 ms
54,116 KB
testcase_11 AC 138 ms
56,196 KB
testcase_12 AC 140 ms
56,424 KB
testcase_13 AC 132 ms
56,192 KB
testcase_14 AC 118 ms
56,296 KB
testcase_15 AC 144 ms
58,620 KB
testcase_16 AC 134 ms
54,600 KB
testcase_17 AC 126 ms
56,192 KB
testcase_18 AC 113 ms
55,936 KB
testcase_19 AC 119 ms
55,920 KB
testcase_20 AC 143 ms
56,448 KB
testcase_21 AC 143 ms
56,676 KB
testcase_22 AC 134 ms
56,556 KB
testcase_23 AC 147 ms
56,544 KB
testcase_24 AC 127 ms
56,196 KB
testcase_25 AC 135 ms
56,704 KB
testcase_26 AC 116 ms
56,040 KB
testcase_27 AC 117 ms
56,056 KB
testcase_28 AC 125 ms
54,296 KB
testcase_29 AC 133 ms
56,168 KB
testcase_30 AC 136 ms
56,292 KB
testcase_31 WA -
testcase_32 AC 142 ms
56,436 KB
testcase_33 AC 83 ms
54,864 KB
testcase_34 AC 54 ms
54,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] values = new int[n];
        List<List<Path>> graph = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < m; i++) {
            graph.get(sc.nextInt() - 1).add(new Path(sc.nextInt() - 1, sc.nextInt()));
        }
        PriorityQueue<Path> queue = new PriorityQueue<>();
        long[] points = new long[n];
        Arrays.fill(points, Long.MIN_VALUE);
        queue.add(new Path(0, 0));
        while (queue.size() > 0) {
            Path p = queue.poll();
            if (p.value < Long.MAX_VALUE) {
                p.value += values[p.idx];
            }
            if (points[p.idx] >= p.value) {
                continue;
            }
            if (points[p.idx] > Long.MIN_VALUE) {
                p.value = Long.MAX_VALUE;
            }
            points[p.idx] = p.value;
            for (Path x : graph.get(p.idx)) {
                queue.add(new Path(x.idx, p.value - (p.value == Long.MAX_VALUE ? 0 : x.value)));
            }
        }
        System.out.println(points[n - 1] == Long.MAX_VALUE ? "inf" : points[n - 1]);
    }
    
    static class Path implements Comparable<Path> {
        int idx;
        long value;
        
        public Path(int idx, long value) {
            this.idx = idx;
            this.value = value;
        }
        
        public int compareTo(Path another) {
            return Long.compare(another.value, value);
        }
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0