Edge List to Adj Mat


Submit solution

Points: 1
Time limit: 4.0s
Memory limit: 512M

Author:
Problem types

For far too long, the war between two raging factions, the Edgians and Adjunds ravished the great plains at the bottom of the sea (plus plus). Fortunately, both factions communicate using heiro-graphs - each graph corresopnds to what we would call a word and to us looks like a directed but unweighted graph.

Unfortunately, Edgians represents heiro-graphs using edge-lists (an edge is specified by two vertices \(u,v\)) but Adjunds use adjacency matrices.

As head-translator for the Great Rally Against Physical Harm (GRAPH), you have been tasked with writing a program that translates an Edgian edge-list to an Adjund adjacency matrix.

Input Specification

The first line contains two integer \(V\), the number of vertices in the graph and \(E\), the number of edges.

The next \(E\) lines contain two space-separated integers \(u, v\), each represents an un-weighted edge from \(u\) to \(v\).

Vertices are labelled from \(0\) to \(V-1\) inclusive.

Output Specification

The same graph given as input but as an adjacency matrix. A \(V \times V\) matrix of 0s or 1s.

Each entry in this matrix \(a_{u,v}\) is either 0 if there is no edge from \(u\) to \(v\) or 1 if there is.

Bounds

For all sub-problems:

\(1 \leq V \leq 1000\)

\(0 \leq E \leq V^2\)

Sample Input 1

4 6
0 3
1 2
2 1
2 3
3 0
3 2

Sample Output 1

0 0 0 1 
0 0 1 0 
0 1 0 1 
1 0 1 0

Sample Input 2

5 9
0 3
1 0
1 4
2 0
2 1
2 4
3 0
3 4
4 0

Sample Output 2

0 0 0 1 0 
1 0 0 0 1 
1 1 0 0 1 
1 0 0 0 1 
1 0 0 0 0

Comments

There are no comments at the moment.