49
2025-05-22 21:35:41
发布于:山西
2阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
struct node{
int from,to,len;
}x[20005];
int dis[2005],vis[2005],n,l=0;
int main(){
cin>>n;
while(true){
int a,b,c;
cin>>a>>b>>c;
if(a==0) break;
x[l].from = a;
x[l].to = b;
x[l].len = c;
l++;
}
dis[1] = 1e9;
queue<int>q;
vis[1] = 1;
q.push(1);
while(!q.empty()){
int f = q.front();
vis[f] = 0;
q.pop();
for(int i = 0;i<l;i++){
int from = x[i].from,to = x[i].to,len = x[i].len;
if(dis[to]<min(dis[from],len)){
dis[to]=min(dis[from],len);
if(!vis[to]){
q.push(to);
vis[to] = 1;
}
}
}
}
for(int i = 2; i <= n; i ++){
cout<<dis[i]<<endl;
}
return 0;
}
这里空空如也
有帮助,赞一个