File tree Expand file tree Collapse file tree 1 file changed +7
-11
lines changed
src/main/kotlin/g3601_3700/s3620_network_recovery_pathways Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,12 @@ package g3601_3700.s3620_network_recovery_pathways
2
2
3
3
// #Hard #Biweekly_Contest_161 #2025_07_22_Time_212_ms_(66.67%)_Space_150.09_MB_(13.33%)
4
4
5
+ import java.util.LinkedList
6
+ import java.util.Queue
5
7
import kotlin.math.max
6
8
7
9
class Solution {
8
- private fun topologicalSort (n : Int , g : List < List <Int >>): List <Int > {
10
+ private fun topologicalSort (n : Int , g : Array < ArrayList <Int >>): List <Int > {
9
11
val indeg = IntArray (n)
10
12
for (i in 0 until n) {
11
13
for (adjNode in g[i]) {
@@ -35,13 +37,13 @@ class Solution {
35
37
private fun check (
36
38
x : Int ,
37
39
n : Int ,
38
- adj : List < List <IntArray >>,
40
+ adj : Array < ArrayList <IntArray >>,
39
41
ts : List <Int >,
40
42
online : BooleanArray ,
41
43
k : Long ,
42
44
): Boolean {
43
45
val d = LongArray (n)
44
- Arrays .fill(d, Long .MAX_VALUE )
46
+ d .fill(Long .MAX_VALUE )
45
47
d[0 ] = 0
46
48
for (u in ts) {
47
49
if (d[u] != Long .MAX_VALUE ) {
@@ -63,14 +65,8 @@ class Solution {
63
65
fun findMaxPathScore (edges : Array <IntArray >, online : BooleanArray , k : Long ): Int {
64
66
val n = online.size
65
67
// Adjacency list for graph with edge weights
66
- val adj = ArrayList <ArrayList <IntArray >>()
67
- for (i in 0 until n) {
68
- adj.add(ArrayList ())
69
- }
70
- val g = ArrayList <ArrayList <Int >>()
71
- for (i in 0 until n) {
72
- g.add(ArrayList ())
73
- }
68
+ val adj = Array <ArrayList <IntArray >>(n) { ArrayList () }
69
+ val g = Array <ArrayList <Int >>(n) { ArrayList () }
74
70
for (e in edges) {
75
71
val u = e[0 ]
76
72
val v = e[1 ]
You can’t perform that action at this time.
0 commit comments