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 |
有大佬帮忙看看我代码吗?感觉好像是这样的#include<iostream> #include<queue> #include<cstring> #include<cmath> using namespace std; const int maxn=1e3+10; int head[maxn]; int dis[maxn]; int n,m,cnt,p,l,x; typedef struct{ int to,w,gra,NXT; }edge; edge e[maxn]; struct node{ int id,dis; node(int id,int dis):id(id),dis(dis){} bool operator <(const node &a)const{ return dis>a.dis; } }; void add(int from,int gra,int to,int w){ e[++cnt].to=to; e[cnt].gra=gra; e[cnt].w=w; e[cnt].NXT=head[from]; head[from]=cnt; } void dijkstra(int s){ priority_queue<node>st; memset(dis,88,sizeof(dis)); dis[s]=0; st.push(node(s,0)); while(!st.empty()){ node f=st.top();st.pop(); int u=f.id;int d=f.dis; if(d!=dis[u])continue; for(int i=head[u];i;i=e[i].NXT){ if((dis[e[i].to]>d+e[i].w)&&abs(e[u].gra-e[e[i].to].gra)<=m){//判断等级 dis[e[i].to]=d+e[i].w; st.push(node(e[i].to,dis[e[i].to])); } } } dis[n]+=e[cnt].w; cout<<dis[n]<<endl; } int main(){ cnt=0; int t,v; scanf("%d%d",&m,&n); for(int i=1;i<=n;i++){ scanf("%d%d%d",&p,&l,&x); add(i,l,i,p); for(int j=1;j<=x;j++){ cin>>t>>v; add(i,l,t,v); } } dijkstra(1); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator