grandes-ecoles 2025 Q9

grandes-ecoles · France · centrale-maths2__official Not Maths
Write, in Python language, a function \texttt{mat\_adj(graph)} which takes as argument a graph of $m \in \mathbb{N}^*$ vertices, directed or undirected, represented by a dictionary having as keys the integers from 0 to $m-1$, and for value associated with such a key the adjacency list of the corresponding vertex, and which returns, respecting the enumeration of the vertices, the adjacency matrix of this graph.
Thus \texttt{mat\_adj(\{0: [1, 2], 1: [0], 2: [0, 1, 2]\})} must return $$[[0,1,1],[1,0,0],[1,1,1]].$$
Write, in Python language, a function \texttt{mat\_adj(graph)} which takes as argument a graph of $m \in \mathbb{N}^*$ vertices, directed or undirected, represented by a dictionary having as keys the integers from 0 to $m-1$, and for value associated with such a key the adjacency list of the corresponding vertex, and which returns, respecting the enumeration of the vertices, the adjacency matrix of this graph.

Thus \texttt{mat\_adj(\{0: [1, 2], 1: [0], 2: [0, 1, 2]\})} must return
$$[[0,1,1],[1,0,0],[1,1,1]].$$