| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
p1000正解不说了,直接贴代码 #include<cstdio> #include<queue> #include<cstring> #define MAXN 100 #define MAXM 10000 using namespace std; struct edge{ int t,l,next; }e[MAXM]; int used,h[MAXN],s,t,dis[MAXN],cnt[MAXN],tf,tt,tl,n,m; bool v[MAXN]; void addedge(int f,int t,int l){//{{{ e[used].t=t; e[used].l=l; e[used].next=h[f]; h[f]=used; used++; }//}}} bool spfa(int s){//{{{ queue<int>q; q.push(s); memset(cnt,0,sizeof(cnt)); memset(dis,0x3f,sizeof(dis)); memset(v,0,sizeof(v)); cnt[s]=1,dis[s]=0,v[s]=true; while(q.size()){ int tmp=q.front(); q.pop(); v[tmp]=false; for(int i=h[tmp];i!=-1;i=e[i].next) if(dis[e[i].t]>dis[tmp]+e[i].l){ dis[e[i].t]=dis[tmp]+e[i].l; if(!v[e[i].t]){ q.push(e[i].t); v[e[i].t]=true; cnt[e[i].t]++; } if(cnt[e[i].t]>n)return false; } } return true; }//}}} int main() { scanf("%d%d",&n,&m); memset(h,-1,sizeof(h)); addedge(1,2,n); addedge(2,3,m); spfa(1); printf("%d",dis[3]); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator