标签:body can ros center using soft inf org poj
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 47803 | Accepted: 14234 |
Description
Input
Output
Sample Input
1 4
10000 3 2
2 8000
3 5000
1000 2 1
4 200
3000 2 1
4 200
50 2 0
Sample Output
5250
Source
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<cstdlib> 5 #include<algorithm> 6 #include<queue> 7 using namespace std; 8 const int N = 105; 9 const int INF = 0x7fffffff; 10 struct Edge{ 11 int value,to,next; 12 }e[N*N]; 13 int dis[N],m,n,ans=INF,head[N],level[N],tot,d; 14 bool exist[N]; 15 bool Judge(int x){ 16 if(level[x]>d+m||level[x]<d)return 0; 17 return 1; 18 } 19 void Add_Edge(int u,int v,int w){ 20 tot++;e[tot].to=v;e[tot].value=w; 21 e[tot].next=head[u];head[u]=tot; 22 } 23 void SPFA(){ 24 memset(dis,0x3f,sizeof(dis)); 25 queue<int>q;dis[0]=0;q.push(0);exist[0]=1; 26 while(!q.empty()){ 27 int u=q.front();q.pop();exist[u]=false; 28 for(int i=head[u];i;i=e[i].next){ 29 int v=e[i].to,w=e[i].value; 30 if(dis[u]+w<dis[v]&&Judge(v)){ 31 dis[v]=w+dis[u]; 32 if(!exist[v]){ q.push(v);exist[v]=true; } 33 } 34 } 35 } 36 ans=min(ans,dis[1]); 37 } 38 int main() 39 { 40 scanf("%d%d",&m,&n); 41 for(int i=1,P,L,X;i<=n;i++){ 42 scanf("%d%d%d",&P,&level[i],&X); 43 Add_Edge(0,i,P); 44 for(int j=1,t,v;j<=X;j++){// 读入每个替代品 45 scanf("%d%d",&t,&v); 46 Add_Edge(t,i,v); 47 } 48 } 49 for(d=level[1]-m;d<=level[1];d++)SPFA(); 50 printf("%d\n",ans); 51 return 0; 52 }
思路:
标签:body can ros center using soft inf org poj
原文地址:http://www.cnblogs.com/suishiguang/p/6492451.html