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 <list> #include<cstring> using namespace std; int n,m; int vis[102]; int dist[102]; int const inf= 0xffffff; typedef pair<int,int>pii; priority_queue<pii,vector<pii>,greater<pii> >q; typedef struct { int t,vi,s; }edge; edge e; list<edge> l[102]; struct object { int p,l; }object[102]; int dijstra(int a) { memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++) { dist[i]=inf; } dist[0]=0; q.push(make_pair(dist[0],0)); while(!q.empty()) { pii u=q.top(); q.pop(); int x=u.second; if(vis[x])continue; vis[x]=true; if(object[x].l<=a&&object[x].l>=a-m) { for(list<edge>::iterator iter=l[x].begin();iter!=l[x].end();iter++) { if(dist[(*iter).t]>dist[x]+(*iter).vi) { dist[(*iter).t]=dist[x]+(*iter).vi; q.push(make_pair(dist[(*iter).t],(*iter).t)); } } } } return dist[1]; } int main() { int x,k; while(cin>>m>>n) { for(int i=1;i<=n;i++) { cin>>object[i].p>>object[i].l>>x; e.s=0;e.t=i;e.vi=object[i].p; l[0].push_back(e); for(int j=1;j<=x;j++) { cin>>e.s>>e.vi; e.t=i; l[e.s].push_back(e); } } int min=100000; for(int i=object[1].l+m;i>0&&i>object[1].l-m;--i) { object[0].l=object[1].l; k=dijstra(i); if(min>k) { min=k; } } cout<<min<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator