Adjacency lists and matrices · Compiler
Adjacency lists and matrices
Build the adjacency matrix of a town's two-way road network. A cell is 1 if a road directly joins its row and column vertices, and 0 otherwise.
- Input
- The first line contains n m. Vertices are numbered 0 through n-1 (1 <= n <= 50, 0 <= m <= 200). Each of the next m lines contains u v for an edge joining u and v in both directions. Endpoints differ and each unordered pair occurs at most once.
- Output
- Print n lines in increasing vertex order. Each line contains n space-separated entries in increasing column order.
Compiler Explorer runs your code when you run or check it.
Loading your exercise draft…