#include#define INF 0x3f3f3f3f //定义一个很大的数using namespace std;const int maxn = 100 + 10;int vis[maxn];int mp[maxn][maxn];int v[maxn][maxn];int dis[maxn];int mon[maxn][maxn];int val[maxn];struct Node { int num; int val;// int sum; }node;priority_queue q;bool operator < (Node a,Node b) { if(a.val = b.val) return a.num > b.num; return a.val > b.val; }int main() {// freopen("in.txt","r",stdin);// int total; int n,m; while(cin>>n>>m) { while(!q.empty()) q.pop();// memset(vis,0,sizeof(vis)); memset(mp,-1,sizeof(mp));// memset(mon,INF,sizeof(mon));// memset(v,0,sizeof(vis));// memset(dis,0,sizeof(dis)); for(int i = 0; i < m; i++) { int t1,t2,c,v; cin>>t1>>t2>>c; mp[t1][t2]=c; mon[t1][t2]=v;// v[a][b] = d; } for(int i = 2; i <= n; i++) { dis[i] = INF; } //1是起始点 dis[1] = 0; node.num = 1; node.val = 0;// node.sum = 0; q.push(node); while(!q.empty()) { for(int i = 2; i <= n; i++) { if(mp[q.top().num][i] != -1&&dis[i] > dis[q.top().num]+mp[q.top().num][i]) { dis[i] = dis[q.top().num] + mp[q.top().num][i]; node.num = i; node.val = dis[i]; q.push(node); } } q.pop(); } for(int i = 1; i <= n; i++) { printf("初始点到%d点的距离为%d\n",i,dis[i]); } } return 0; }