# poj1062 昂贵的聘礼

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
/*

*/
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#define ll long long
using namespace std;
const int maxn = 20005;
const ll inf = 987654321234LL;
char ch=getchar();
int x=0,f=1;
while(!(ch>='0'&&ch<='9')){if(ch=='-')f=-1;ch=getchar();};
while(ch>='0'&&ch<='9'){x=x*10+(ch-'0');ch=getchar();};
return x*f;
}
struct edge{
int v;
int w;
int nxt;
}e[maxn*3];
int n,m;
int p[maxn],l[maxn],sz[maxn];
int t,v;
int flag,vis[maxn];
ll dis[maxn],ans;
void ins(int u,int v,int w){
cnt++;
e[cnt].v = v;
e[cnt].w = w;
}
void spfa(int t){
flag++;
dis[0] = 0;
for(int i = 1;i <= n;i++) dis[i] = inf;
queue<int> q;
vis[0] = flag;
q.push(0);
int now,to;
while(!q.empty()){
now = q.front();
q.pop();
for(int i = head[now];i;i = e[i].nxt){
to = e[i].v;
if(dis[to] > dis[now] + e[i].w && l[to] >= t && l[to] <= t+m){
dis[to] = dis[now] + e[i].w;
if(vis[to] != flag){
vis[to] = flag;
q.push(to);
}
}
}
vis[now] = false;
}
ans = min(ans,dis[1]);
}
int main(){
for(int i = 1;i <= n;i++){
ins(0,i,p[i]);
for(int j = 1;j <= sz[i];j++){
ins(t,i,v);
}
}
ans = inf;
for(int i = l[1] - m;i <= l[1];i++) spfa(i);
cout<<ans;
return 0;
}

posted @ 2016-09-29 19:14  ACforever  阅读(198)  评论(0编辑  收藏  举报