Edge list to adjacency matrix, undirected variant
Problem
A simple undirected graph is given a list of edges, output its representation as an adjacency matrix.
Input:
- the first line sets numbers n
(\(1<=n<=100\)) – the number of vertices in the graph and m
(\(1<=m<=n(n - 1)/2\)) – number of ribs;
- followed by m
pairs of numbers – graph edges (each pair of numbers on a separate line).
Output: print the adjacency matrix of the given graph.
Examples
# |
Input |
Output |
1 |
5 3
1 3
2 3
2 5
|
0 0 1 0 0
0 0 1 0 1
1 1 0 0 0
0 0 0 0 0
0 1 0 0 0
|