标签:cst 贵的 bool 昂贵的聘礼 min code pac queue cstring
#include<iostream> #include<queue> #include<cstring> using namespace std; const int N=1e6+10,INF=0x3f3f3f3f; int h[N],ne[N],e[N],w[N],idx; int dist[N]; bool st[N]; int n,m,s=0; int grade[N]; void add(int a,int b,int c) { e[idx]=b; w[idx]=c; ne[idx]=h[a]; h[a]=idx++; } int spfa(int x) { int l=x,r=x+m; queue<int>q; memset(dist,0x3f,sizeof dist); memset(st,0,sizeof st); dist[s]=0; q.push(s); st[s]=1; while(q.size()) { int t=q.front(); q.pop(); st[t]=false; for(int i=h[t];i!=-1;i=ne[i]) { int j=e[i]; if(grade[j]<l||grade[j]>r) continue; if(dist[j]>dist[t]+w[i]) { dist[j]=dist[t]+w[i]; if(!st[j]) { st[j]=1; q.push(j); } } } } return dist[1]; } int main() { cin>>m>>n; memset(h,-1,sizeof h); for(int i=1;i<=n;i++) { int p,x; cin>>p>>grade[i]>>x; add(s,i,p); while(x--) { int t,v; cin>>t>>v; add(t,i,v); } } int res=INF; for(int i=grade[1]-m;i<=grade[1];i++) res=min(res,spfa(i)); cout<<res<<endl; return 0; }
标签:cst 贵的 bool 昂贵的聘礼 min code pac queue cstring
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12239854.html