Skip to content

Graph

Graph

The current toolchain does not yet ship a queue or heap module, so classic BFS and Dijkstra implementations are not ergonomic in the live stdlib. DFS-style recursion over an implicit graph is available today.

Current status by problem

ProblemCurrent status
BFS shortest pathblocked by missing queue module
DFS traversalavailable over implicit graphs or fixed recursive structure
Dijkstra with heapblocked by missing heap / priority queue module

Verified pattern: DFS over an implicit binary tree

func dfs_sum(node: i32, limit: i32) -> i32:
if (node > limit):
return 0
return node + dfs_sum(node * 2, limit) + dfs_sum(node * 2 + 1, limit)

Time complexity: O(n) over visited nodes
Space complexity: O(h) recursion depth

Verified pattern: reachability in an implicit graph

func reaches(target: i32, node: i32, limit: i32) -> bool:
if (node == target):
return true
if (node > limit):
return false
if (reaches(target, node * 2, limit)):
return true
return reaches(target, node * 2 + 1, limit)

Time complexity: O(n) in the explored region
Space complexity: O(h) recursion depth

What is missing for full contest graph support

  • queue-backed BFS
  • heap-backed Dijkstra
  • vector-backed adjacency lists
  • map/set helpers for visited-state bookkeeping