嗯!可以运行!!
贴代码:
<注>如果是有向图,稍微改一下也能用
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cmath>
#include<set>
typedef long long ll;
using namespace std;
const int maxn = 130;
const int MAX = 1e5;
struct Node {
char vexs[maxn]; //顶点表
int arc[maxn][maxn]; //邻接矩阵
int v, e; //顶点数,边数
}G;
void Create(Node &G) {
int i, j, k,w;
cin >> G.v >> G.e; //输入顶点数,边数
for (i = 1; i <= G.v; i++)
cin >> G.vexs[i]; //输入顶点(char)
for (i = 1; i <= G.v; i++)
for (j = 1; j <= G.v; j++)
G.arc[i][j] = MAX; //初始化边数为无穷大
for (k = 1; k <= G.e; k++) {
cin >> i >> j >> w; //输入边的位置及权值
G.arc[i][j] = w;
G.arc[j][i] = G.arc[i][j];//无向图是对称的
}
}
int main()
{
Create(G);
for (int i = 1; i <= G.v; i++) {
for (int j = 1; j <= G.v; j++)
cout << G.arc[i][j] << " ";
cout << endl;
}
return 0;
}