File tree Expand file tree Collapse file tree 2 files changed +4
-4
lines changed Expand file tree Collapse file tree 2 files changed +4
-4
lines changed Original file line number Diff line number Diff line change 9
9
let lines = toSeq (" agraph" .lines)
10
10
let numNodes = lines[0 ].parseInt
11
11
var nodes = newSeqWith (numNodes, Node (neighbours: newSeq [Route ]()))
12
+ var visited = newSeq [bool ](numNodes)
12
13
13
14
for i in 1 .. lines.high:
14
15
let nums = lines[i].split (' ' )
@@ -21,11 +22,9 @@ for i in 1..lines.high:
21
22
22
23
nodes[node].neighbours.add (Route (dest: neighbour, cost: cost))
23
24
24
- var visited = newSeq [bool ](numNodes)
25
- let start = cpuTime ()
26
-
27
25
proc getLongestPath (nodeId: int ): int =
28
26
visited[nodeId] = true
27
+
29
28
for neighbour in nodes[nodeId].neighbours:
30
29
if not visited[neighbour.dest]:
31
30
let dist = neighbour.cost + getLongestPath (neighbour.dest)
@@ -34,7 +33,8 @@ proc getLongestPath(nodeId: int): int =
34
33
35
34
visited[nodeId] = false
36
35
37
- let result = getLongestPath (0 )
36
+ let start = cpuTime ()
37
+ let result = getLongestPath (0 )
38
38
let duration = cpuTime () - start
39
39
40
40
echo result , " LANGUAGE Nim " , int (duration * 1000 )
You can’t perform that action at this time.
0 commit comments