/*** 邻接矩阵定义、创建邻接矩阵* * ①算法思想** ②算法设计*/#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <malloc.h>
#include <cstdlib>
#define MaxSize 20
#define INF 999999//1、邻接矩阵
//无向图、有向图
struct MGraph{char Vex[MaxSize];//保存每个节点的权值,很多时候是用stringint Edge[MaxSize][MaxSize];//保存边上权值int VexNum,ArcNum;//储存顶点个数和边的个数
};//带权图(网)
struct MGraphW{char Vex[MaxSize];//保存每个节点的权值,很多时候是用stringint Weight[MaxSize][MaxSize];//保存边上权值int VexNum,ArcNum;//储存顶点个数和边的个数
};//创建邻接矩阵
//①有向图
MGraph CreatMGraphX(){MGraph G;scanf("%d %d",&G.VexNum,&G.ArcNum);for (int i = 0; i < G.VexNum; ++i) {for (int j = 0; j < G.VexNum; ++j) {G.Edge[i][j] = 0;//初始化}}int v1,v2;//输入有边连接的两个顶点for (int i = 0; i < G.ArcNum; ++i) {scanf("%d%d",&v1,&v2);G.Edge[v1][v2] = 1;}return G;
}
//②有向带权图(网)
MGraphW CreatMGraphWX(){MGraphW G;scanf("%d%d",&G.VexNum,&G.ArcNum);for (int i = 0; i < G.VexNum; ++i) {for (int j = 0; j < G.VexNum; ++j) {G.Weight[i][j] = INF;//初始化}}int v1,v2,w;for (int i = 0; i < G.ArcNum; ++i) {scanf("%d%d%d",&v1,&v2,&w);G.Weight[v1][v2] = w;}return G;
}
//③无向图
MGraph CreatMGraph(){MGraph G;scanf("%d%d",&G.VexNum,&G.ArcNum);for (int i = 0; i <G.VexNum; ++i) {for (int j = 0; j < G.VexNum; ++j) {G.Edge[i][j] = 0;}}int v1,v2;for (int i = 0; i < G.ArcNum; ++i) {scanf("%d%d",&v1,&v2);G.Edge[v1][v2] = G.Edge[v1][v2] = 1;}return G;
}
//④无向带权图(网)
MGraph CreatMGraphW(){MGraphW G;scanf("%d%d",&G.VexNum,&G.ArcNum);for (int i = 0; i < G.VexNum; ++i) {for (int j = 0; j < G.VexNum; ++j) {G.Weight[i][j] = INF;}}int v1,v2,w;for (int i = 0; i <G.VexNum; ++i) {scanf("%d%d%d",&v1,&v2,&w);G.Weight[v1][v2] = G.Weight[v1][v2] = w;}return G;
}