結果
問題 | No.468 役に立つ競技プログラミング実践編 |
ユーザー | uafr_cs |
提出日時 | 2017-11-01 23:32:43 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,551 bytes |
コンパイル時間 | 3,915 ms |
コンパイル使用メモリ | 84,192 KB |
実行使用メモリ | 159,256 KB |
最終ジャッジ日時 | 2023-08-14 16:17:51 |
合計ジャッジ時間 | 39,181 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 174 ms
56,504 KB |
testcase_01 | AC | 171 ms
57,212 KB |
testcase_02 | AC | 173 ms
56,932 KB |
testcase_03 | AC | 222 ms
60,140 KB |
testcase_04 | AC | 178 ms
54,968 KB |
testcase_05 | AC | 222 ms
60,004 KB |
testcase_06 | AC | 220 ms
59,020 KB |
testcase_07 | AC | 219 ms
60,380 KB |
testcase_08 | AC | 222 ms
60,816 KB |
testcase_09 | AC | 222 ms
59,404 KB |
testcase_10 | AC | 218 ms
60,692 KB |
testcase_11 | AC | 221 ms
61,188 KB |
testcase_12 | AC | 224 ms
60,524 KB |
testcase_13 | AC | 232 ms
60,648 KB |
testcase_14 | AC | 313 ms
61,720 KB |
testcase_15 | AC | 314 ms
61,216 KB |
testcase_16 | AC | 317 ms
61,436 KB |
testcase_17 | AC | 314 ms
61,328 KB |
testcase_18 | AC | 320 ms
62,616 KB |
testcase_19 | AC | 314 ms
61,796 KB |
testcase_20 | AC | 309 ms
61,388 KB |
testcase_21 | AC | 326 ms
61,576 KB |
testcase_22 | AC | 301 ms
61,068 KB |
testcase_23 | AC | 316 ms
61,920 KB |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
testcase_34 | AC | 1,276 ms
124,976 KB |
testcase_35 | AC | 270 ms
62,000 KB |
testcase_36 | AC | 189 ms
56,864 KB |
ソースコード
import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.Map.Entry; import java.util.Scanner; public class Main { public static final long INF = Long.MAX_VALUE / 2 - 1; public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final int M = sc.nextInt(); ArrayList<HashMap<Integer, Long>> fwd_adj = new ArrayList<HashMap<Integer, Long>>(); ArrayList<HashMap<Integer, Long>> rev_adj = new ArrayList<HashMap<Integer, Long>>(); for(int i = 0; i < N; i++){ fwd_adj.add(new HashMap<Integer, Long>()); rev_adj.add(new HashMap<Integer, Long>()); } int[] in_degs = new int[N]; int[] out_degs = new int[N]; for(int i = 0; i < M; i++){ final int A = sc.nextInt(); final int B = sc.nextInt(); final long C = sc.nextLong(); fwd_adj.get(A).put(B, C); rev_adj.get(B).put(A, C); in_degs[B]++; out_degs[A]++; } long[] max_path = new long[N]; long[] rev_max_path = new long[N]; Arrays.fill(max_path, -1); Arrays.fill(rev_max_path, -1); max_path[0] = 0; LinkedList<Integer> queue = new LinkedList<>(); for(int i = 0; i < N; i++){ if(in_degs[i] != 0){ continue; } queue.add(i); } while(!queue.isEmpty()){ final int node = queue.poll(); for(final Entry<Integer, Long> entry : fwd_adj.get(node).entrySet()){ final int next = entry.getKey(); final long cost = max_path[node] + entry.getValue(); if(max_path[next] < 0 || max_path[next] < cost){ max_path[next] = cost; } in_degs[next]--; if(in_degs[next] == 0){ queue.add(next); } } } rev_max_path[N - 1] = max_path[N - 1]; for(int i = 0; i < N; i++){ if(out_degs[i] != 0){ continue; } queue.add(i); } while(!queue.isEmpty()){ final int node = queue.poll(); for(final Entry<Integer, Long> entry : rev_adj.get(node).entrySet()){ final int prev = entry.getKey(); final long cost = rev_max_path[node] - entry.getValue(); if(rev_max_path[prev] < 0 || rev_max_path[prev] > cost){ rev_max_path[prev] = cost; } out_degs[prev]--; if(out_degs[prev] == 0){ queue.add(prev); } } } int count = 0; for(int i = 0; i < N; i++){ if(max_path[i] != rev_max_path[i]){ count++; } } System.out.println(max_path[N-1] + " " + count + "/" + N); //System.out.println(Arrays.toString(max_path)); //System.out.println(Arrays.toString(rev_max_path)); } }