Adjacency list built edge by edge
adj[u].push(v) per read edge: Graph.undirected(es) / Graph.directed(es)
let (n, m): (1..=200000, 0..=200000) = read()
var adj: List<List<Int>> = [[] for _ in 0..=n]
for _ in 0..m:
let (u, v): (1..=n, 1..=n) = read()
adj[u].push(v)
print(adj[1].len)let (n, m): (1..=200000, 0..=200000) = read()
domain V = 1..=n
domain E = 0..m
let es: [E](u: V, v: V) = read()
let g = Graph.directed(es)
print(g.deg(1))Why
vector<vector<int>> adj(n + 1) filled by adj[u].push_back(v) as each edge is read is how C++ stores a graph, and [[] for _ in 0..=n] with adj[u].push(v) is its literal translation: n + 1 separate lists, a wasted slot 0, and vertex numbers that are plain Ints. CP Lang reads the whole edge list at once, let es: [E](u: V, v: V) = read() with domain V = 1..=n and domain E = 0..m, and std.graph builds the graph from it: Graph.undirected(es) stores both arcs of each edge, Graph.directed(es) one, in a single compact block that keeps input order. Every vertex is a V, so a vertex from another index space, or a 0 from a 1-based input, is a type error rather than a silent read. bfs, dijkstra, components and the rest take the graph as it is. A graph that keeps growing after input stays a [V]List<V>.
The lint fires on a var list of lists (or [D]List<T>) started empty that a for loop pushes into right after reading a value. It has no fix, since the vertex and edge domains need declaring.
The practice it serves
A hand-written pattern the language or the standard library already says in one step. Family: S.graph.
Not flagged
A near miss: close to the pattern, but not it.
let n: 1..=100 = read()
let a: [0..n]Int = read()
var by_mod: List<List<Int>> = [[] for _ in 0..3]
for x in a:
by_mod[x % 3].push(x)
print(by_mod[0].len)Turn it off
For one block, wrap it in with lint(manual_adjacency_list: allow):. For a project, add manual_adjacency_list = "allow" under [lints] in cp.toml.
Generated from spec/lints/manual_adjacency_list, the same record the linter is built from.