import java.util.Scanner;
public class GraphMatrix {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入节点个数和边的个数:");
int n = sc.nextInt();
int m = sc.nextInt();
int[][] matrix = new int[n][m];
System.out.println("请依次输入每条边连接的两个节点编号:");
for (int i = 0; i < m; i++) {
int u = sc.nextInt() - 1;
int v = sc.nextInt() - 1;
matrix[u][i] = 1;
matrix[v][i] = 1;
}
System.out.println("无向图的关联矩阵为:");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
}
}