buildGraph function
Builds an unweighted Adjacency list from edges, where nodeCount is the
max node index + 1. Edges referencing out-of-range nodes are skipped.
Example:
buildGraph([(0, 1), (1, 2)], 3); // [[1], [2], []]
Implementation
Adjacency buildGraph(List<(int, int)> edges, int nodeCount) {
final Adjacency adj = List.generate(nodeCount, (_) => <int>[]);
for (final (int u, int v) in edges) {
if (u >= 0 && u < nodeCount && v >= 0 && v < nodeCount) {
adj[u].add(v);
}
}
return adj;
}