Skip to content

Commit 08f5b58

Browse files
committed
Reorder in Nim
1 parent a884530 commit 08f5b58

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

cpp

-17.5 KB
Binary file not shown.

nim.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type
99
let lines = toSeq("agraph".lines)
1010
let numNodes = lines[0].parseInt
1111
var nodes = newSeqWith(numNodes, Node(neighbours: newSeq[Route]()))
12+
var visited = newSeq[bool](numNodes)
1213

1314
for i in 1..lines.high:
1415
let nums = lines[i].split(' ')
@@ -21,11 +22,9 @@ for i in 1..lines.high:
2122

2223
nodes[node].neighbours.add(Route(dest: neighbour, cost: cost))
2324

24-
var visited = newSeq[bool](numNodes)
25-
let start = cpuTime()
26-
2725
proc getLongestPath(nodeId: int): int =
2826
visited[nodeId] = true
27+
2928
for neighbour in nodes[nodeId].neighbours:
3029
if not visited[neighbour.dest]:
3130
let dist = neighbour.cost + getLongestPath(neighbour.dest)
@@ -34,7 +33,8 @@ proc getLongestPath(nodeId: int): int =
3433

3534
visited[nodeId] = false
3635

37-
let result = getLongestPath(0)
36+
let start = cpuTime()
37+
let result = getLongestPath(0)
3838
let duration = cpuTime() - start
3939

4040
echo result, " LANGUAGE Nim ", int(duration * 1000)

0 commit comments

Comments
 (0)