結果
| 問題 | No.468 役に立つ競技プログラミング実践編 |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-12-24 13:09:11 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,388 ms / 2,000 ms |
| コード長 | 1,983 bytes |
| 記録 | |
| コンパイル時間 | 2,602 ms |
| コンパイル使用メモリ | 80,552 KB |
| 実行使用メモリ | 132,492 KB |
| 最終ジャッジ日時 | 2024-09-21 16:53:50 |
| 合計ジャッジ時間 | 21,274 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 31 |
| other | AC * 6 |
ソースコード
import java.util.*;
import java.io.*;
public class Main {
static ArrayList<HashMap<Integer, Integer>> graph = new ArrayList<>();
static ArrayList<HashMap<Integer, Integer>> rgraph = new ArrayList<>();
static int[] costs;
static int[] rcosts;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] first = br.readLine().split(" ", 2);
int n = Integer.parseInt(first[0]);
int m = Integer.parseInt(first[1]);
for (int i = 0; i < n; i++) {
graph.add(new HashMap<>());
rgraph.add(new HashMap<>());
}
for (int i = 0; i < m; i++) {
String[] line = br.readLine().split(" ", 3);
int a = Integer.parseInt(line[0]);
int b = Integer.parseInt(line[1]);
int c = Integer.parseInt(line[2]);
graph.get(a).put(b, c);
rgraph.get(b).put(a, c);
}
costs = new int[n];
Arrays.fill(costs, -1);
costs[0] = 0;
dfw(n - 1);
rcosts = new int[n];
Arrays.fill(rcosts, Integer.MAX_VALUE);
rcosts[n - 1] = costs[n - 1];
rdfw(0);
int ans = 0;
for (int i = 0; i < n; i++) {
if (costs[i] < rcosts[i]) {
ans++;
}
}
System.out.println(costs[n - 1] + " " + ans + "/" + n);
}
static int rdfw(int idx) {
if (rcosts[idx] == Integer.MAX_VALUE) {
for (int x : graph.get(idx).keySet()) {
rcosts[idx] = Math.min(rcosts[idx], rdfw(x) - graph.get(idx).get(x));
}
}
return rcosts[idx];
}
static int dfw(int idx) {
if (costs[idx] < 0) {
for (int x : rgraph.get(idx).keySet()) {
costs[idx] = Math.max(costs[idx], dfw(x) + rgraph.get(idx).get(x));
}
}
return costs[idx];
}
}
tenten