o1-mini-2024-09-12· OpenAI
WildChat-4.8M (AI2)
use c++. use short naming. do not use comments. do not use inline functions. Edge list…
- User
use c++. use short naming. do not use comments. do not use inline functions. Edge list to adjacency matrix, directed option Input file: stdin
Output file: stdout
Time limit: 1 sec
Memory limit: 256 mb
A simple directed graph is given by a list of edges. Print its representation as an adjacency matrix.
Input The input of the program is the numbers n (1≤n≤100 ) — the number of vertices in the graph and m (1≤m≤n(n−1) ) — number of edges. Then follows m pairs of numbers — edges of the graph.
Output Output the adjacency matrix of the given graph.
Examples Input 1:
copy
5 3 1 3 2 3 5 2
Output 1:
copy
0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
- Assistantcpp
#include<bits/stdc++.h> using namespace std; int main(){ int n,m; cin>>n>>m; int mat[100][100]; memset(mat,0,sizeof(mat)); for(int i=0;i<m;i++){int a,b; cin>>a>>b; mat[a-1][b-1]=1;} for(int i=0;i<n;i++){for(int j=0;j<n;j++) cout<<mat[i][j]<<" "; cout<<'\n';} }