您现在的位置是:主页 > news > 用自己的计算机做服务器建网站/安徽网络推广

用自己的计算机做服务器建网站/安徽网络推广

admin2025/5/14 11:45:08news

简介用自己的计算机做服务器建网站,安徽网络推广,南昌网站建设一般多少钱一年,做课件网站★☆ 输入文件:djs.in 输出文件:djs.out 简单对比 时间限制:3 s 内存限制:128 MB 过暑假了,阿杜准备出行旅游,他已经查到了某些城市的两两之间的距离及可行路线(可行路线有方向),如下图…

用自己的计算机做服务器建网站,安徽网络推广,南昌网站建设一般多少钱一年,做课件网站★☆ 输入文件:djs.in 输出文件:djs.out 简单对比 时间限制:3 s 内存限制:128 MB 过暑假了,阿杜准备出行旅游,他已经查到了某些城市的两两之间的距离及可行路线(可行路线有方向),如下图…

★☆   输入文件:djs.in   输出文件:djs.out   简单对比

时间限制:3 s   内存限制:128 MB

过暑假了,阿杜准备出行旅游,他已经查到了某些城市的两两之间的距离及可行路线(可行路线有方向),如下图所示。请你编程计算从阿杜所住城市到其它城市的最短路径以帮助阿杜制定旅行计划。

【输入格式】

输入由若干行组成,第一行有三个整数,n1n100m1mn2v1mn;城市数,m城市间道路数,v是阿杜所住城市。第2m+1行是每条路的信息,每行三个整数,为道路的起点、终点和两城市间距离。(城市从0开始编号)

【输出格式】

n组(按城市编号由小至大),每组三行

第一行:城市编号及一个冒号

第二行:path及一个冒号,后面是最短路径节点编号序列(编号间用一个空格隔开)

第三行:cost及一个冒号,后面是一个整数,表示路径距离

如果没有通路则输出 no

【输入样例】

6 8 0
0 2 10
0 4 30
0 5 100
1 2 5
2 3 50
3 5 10
4 3 20
4 5 60

【输出样例】

0:
no
1:
no
2:
path:0 2
cost:10
3:
path:0 4 3
cost:50
4:
path:0 4
cost:30
5:
path:0 4 3 5
cost:60

spfa+路径输出(要求的前驱结点,在路程小的情况下编号最小):
#include<iostream>
#include<cstdio>
#include<queue>using namespace std;
const int N=110;
const int Maxn=9999999;int dis[N],pre[N],fitpre[N],head[N];
bool vis[N];
int n,m,start,now=1,js;
queue<int>q;
struct node{int u,v,w,nxt;
}E[N*N];inline int read()
{int x=0;char c=getchar();while(c<'0'||c>'9')c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x;
}inline void add(int u,int v,int w)
{E[now].v=v;E[now].w=w;E[now].nxt=head[u];head[u]=now++;
}inline int spfa(int start,int endd)
{for(int i=0;i<n;i++)dis[i]=Maxn,pre[i]=0;dis[start]=0;vis[start]=1;q.push(start);while(!q.empty()){int top=q.front();q.pop();vis[top]=0;for(int i=head[top];~i;i=E[i].nxt){if(dis[E[i].v]>dis[top]+E[i].w){dis[E[i].v]=dis[top]+E[i].w;pre[E[i].v]=top;if(!vis[E[i].v])q.push(E[i].v),vis[E[i].v]=1;}if(dis[E[i].v]==dis[top]+E[i].w)pre[E[i].v]=min(pre[E[i].v],top);}    }return dis[endd];
}int main()
{freopen("djs.in","r",stdin);freopen("djs.out","w",stdout);n=read(),m=read(),start=read();for(int i=0;i<n;i++)head[i]=-1;for(;m;m--){int u=read(),v=read(),w=read();add(u,v,w);}for(int i=0;i<n;i++)if(i==start)printf("%d:\nno\n",i);else{int diss=spfa(start,i);if(diss==Maxn)printf("%d:\nno\n",i);else{printf("%d:\n",i);printf("path:");js=0;int ii=i;while(ii!=start){fitpre[++js]=ii;ii=pre[ii];}fitpre[++js]=start;for(int j=js;j>0;j--)printf("%d ",fitpre[j]);printf("\ncost:%d\n",diss);}    }return 0;
}

 



转载于:https://www.cnblogs.com/lyqlyq/p/7137535.html