class
AtCoder::Graph(NodeInfo, EdgeInfo)
- AtCoder::Graph(NodeInfo, EdgeInfo)
- Reference
- Object
Direct Known Subclasses
Defined in:
graph.crConstructors
Instance Method Summary
-
#dfs(node : Int64, initial_value : T, &block : Int64, T, NamedTuple(node: Int64, node_info: NodeInfo | Nil, edge: Int64 | Nil, edge_info: EdgeInfo | Nil, parent: Int64), T -> -> ) forall T
Performs a depth-first search from
node. -
#dijkstra(start_node)
Performs Dijkstra's Algorithm to calculate the distance of each node from
start_node. - #visited : Set(Int64)
Constructor Detail
Instance Method Detail
Performs a depth-first search from node.
The block is called for each visited node with (node, value, info, callback), where value
is the value passed from the parent (initial_value for node itself) and info holds the
node, its NodeInfo, the edge from the parent and its EdgeInfo, and the parent (-1 for
node itself). Calling callback.call(new_value) visits the children of the node with
new_value; if the block does not call it, the children are not visited from this node.
The search uses an explicit stack, so it does not overflow the call stack on deep graphs.
Nodes are visited in the same order as a recursive DFS, but the children are visited
after the block returns, not inside callback.call. If callback is called more than
once, the last value is used.
Performs Dijkstra's Algorithm to calculate the distance of each node from start_node.
To use this method, EdgeInfo must implement .zero and #+(EdgeInfo) and #>(EdgeInfo).