package Text4;
import java.io.*;
import java.util.*;
public class Graph{
int vertex; //顶点数
int edges; //边数
static int [][] matrix ; //邻接矩阵
public static void main(String[] args){
try(
Scanner scanner = new Scanner(new File("d:/tinyG.txt"));
PrintWriter fout = new PrintWriter(new File("d:/tinyG_matrix.txt"));){
int vertex = scanner.nextInt(); //顶点的数目
int edges = scanner.nextInt(); //边的数目
matrix = new int[vertex][vertex];//读取每条边对应的两个顶点,设置邻接矩阵的值
for (int i = 0; i < edges; i++) {
int v1 = scanner.nextInt();
int v2 = scanner.nextInt();
matrix[v1][v2] = 1;
matrix[v2][v1] = 1;
}
//无向图的邻接矩阵写入指定文件d:/tinyG_matrix.txt中
for(int i=0; i<vertex; i++){
for(int j=0; j<vertex; j++){
fout.print(matrix[i][j] + " ");
}
fout.println();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}