标签:tween table rails 4 pos integer sample rect class org
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 58225 | Accepted: 19854 |
Description
Input
Output
Sample Input
5 5 1 2 20 2 3 30 3 4 20 4 5 20 1 5 100
Sample Output
90
Hint
Source
#include<iostream> #include<queue> #include<cstring> #include<cstdio> #define maxn 1002 using namespace std; queue<int>q; int head[maxn],dis[maxn],inq[maxn]; int sumedge,t,n,x,y,z; struct Edge{ int x,y,z,nxt; Edge(int x=0,int y=0,int z=0,int nxt=0): x(x),y(y),z(z),nxt(nxt){} }edge[maxn<<2]; void add(int x,int y,int z){ edge[++sumedge]=Edge(x,y,z,head[x]); head[x]=sumedge; } void spfa(){ memset(dis,0x3f,sizeof(dis)); dis[1]=0;inq[1]=1;q.push(1); while(!q.empty()){ int now=q.front();q.pop();inq[now]=0;//经常忘了 for(int i=head[now];i;i=edge[i].nxt){ int v=edge[i].y; if(dis[v]>dis[now]+edge[i].z){ dis[v]=dis[now]+edge[i].z; if(!inq[v]){ inq[v]=1;q.push(v); } } } } } int main(){ scanf("%d%d",&t,&n); for(int i=1;i<=t;i++){ scanf("%d%d%d",&x,&y,&z); add(x,y,z);add(y,x,z); } spfa(); printf("%d\n",dis[n]); return 0; }
标签:tween table rails 4 pos integer sample rect class org
原文地址:http://www.cnblogs.com/zzyh/p/7435399.html