Constructs a graph using a 1D-array-based Compressed Sparse Row (CSR) format. This structure is highly optimized for fast traversal in algorithms like Dijkstra's. Separating the graph construction from the path-finding algorithm avoids redundant processing when running algorithms multiple times on the same graph.
Arguments
- n
an integer specifying the number of nodes (vertices) in the graph.
- u
an integer vector of the starting nodes for each edge (1-indexed).
- v
an integer vector of the ending nodes for each edge (1-indexed).
- w
a numeric vector of edge weights (costs).
- directed
a logical value indicating whether the graph is directed. Defaults to
FALSE(undirected).
