Adjacency matrix from edge list EASY Grafuri (BAC) 10 XP 0 solved
Mobile coding works. A laptop is faster for long sessions.

Problem

An undirected graph has `n` vertices numbered from `1` to `n` and `m` edges. Read the edge list and print the adjacency matrix of the graph. Recall that the adjacency matrix `A` of an undirected graph has `A[i][j] = 1` if there is an edge between vertices `i` and `j`, and `A[i][j] = 0` otherwise. The main diagonal contains only zeros (the graph has no self-loops). Input: The first line contains two natural numbers `n` and `m`, separated by a space. The following `m` lines each contain two natural numbers `x` and `y` representing an edge between vertices `x` and `y`. - `1 <= n <= 50` - `0 <= m <= n*(n-1)/2` - `1 <= x, y <= n`, `x != y` - the graph contains no duplicate edges Output: The program prints the adjacency matrix, with values on the same row separated by a single space, one matrix row per output line. Example: Input: 5 4 1 2 1 3 2 4 3 5 Output: 0 1 1 0 0 1 0 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 0

Ready to solve this challenge?

Create a free account to write code, submit solutions, and track your progress.

⌨️ Keyboard Shortcuts

Code Editor
Run Code
Ctrl Enter
Submit Code
Ctrl Shift Enter
Format Code
Shift Alt F
Toggle Comment
Ctrl /
Undo
Ctrl Z
Redo
Ctrl Y
Navigation
Global Search
/
Show Shortcuts
?
Close Modal
Esc

🔍 Interactive Debugger

0 / 0

Analyzing your code...

📦 Variables

No variables yet

📚 Call Stack
main() line 1
📤 Output
We use cookies

Essential cookies are always active. You can choose to enable preference and analytics cookies. Learn more