From d4e97d77f76e2aff69a1ff83dbbfd3ccfefb6fdf Mon Sep 17 00:00:00 2001 From: Mrhongxing <154480715+Mrhongxing@users.noreply.github.com> Date: Sun, 25 Oct 2026 14:00:47 +0800 Subject: [PATCH] Create A2050.java --- src/com/hong/www/A2050.java | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/com/hong/www/A2050.java diff --git a/src/com/hong/www/A2050.java b/src/com/hong/www/A2050.java new file mode 100644 index 0000000..8f0a79f --- /dev/null +++ b/src/com/hong/www/A2050.java @@ -0,0 +1,38 @@ +package com.hong.www; + +import java.util.*; + +public class A2050 { + public int minimumTime(int n, int[][] relations, int[] time) { + HashMap map = new HashMap<>(); + HashMap> map2 = new HashMap<>(); + PriorityQueue temp = new PriorityQueue<>((a, b) -> a[1] - b[1]); + int s=0; + for (int[] x : relations) { + map.put(x[1], map.getOrDefault(x[1], 0) + 1); + map2.computeIfAbsent(x[0], k -> new ArrayList<>()).add(x[1]); + } + for (int i = 0; i < n; i++) { + if (!map.containsKey(i + 1)) { + temp.add(new int[] { i+1, time[i] }); + } + } + while (!temp.isEmpty()) { + int[] now = temp.poll(); + if(now[1]>s){ + s=now[1]; + } + for (int x : map2.getOrDefault(now[0], new ArrayList<>())) { + if (map.containsKey(x)) { + map.put(x, map.get(x) - 1); + if (map.get(x) == 0) { + map.remove(x); + temp.offer(new int[] { x, now[1] + time[x-1]}); + } + } + } + } + return s; + } + +}