求一个点到另外一个点的最小距离 #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<vector> #include<cstring> #include<cstdio> #include<cmath> #include<cstdlib> #include<sstream> #include<string> #include<map> using namespace std; typedef long long ll; int dx[4] = { 0, 0, 1, -1 }; int dy[4] = { 1, -1, 0, 0 }; #define fo(i,l,r) for (int i = l; i <= r; ++i) #define F 10005 int n, m, s, t,x,y,ww; ll D[F],w[F][F],vis[F]; int main() { cin >> n >> m >> s >> t; fo(i, 1, n) fo(j, 1, n) { if (i != j) w[i][j] = 0x3f3f3f3f3f; } fo(i, 0, n)//注意0的初始化 D[i] = 0x3f3f3f3f3f; D[s] = 0;//从源点到i的距离 fo(i, 1, m) { scanf("%d%d%d", &x, &y, &ww); w[x][y] = ww; w[y][x] = ww; } //dijkstra算法 int k = 0; fo(i, 1, n) { k = 0; fo(j, 1, n) if (!vis[j] && D[j] < D[k])//一开始找源点 k = j; vis[k] = 1; fo(j, 1, n) if (!vis[j]&&D[k] + w[k][j] < D[j]) { D[j] = D[k] + w[k][j]; } } cout << D[t] << endl; return 0; }不用任何容器来实现这个代码