标签:
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 110
#define M 10100
#define INF 0x3f3f3f3f
using namespace std;
int n,m,K,e,d,cnt;
int v[N],can[N],f[N];
struct node
{
int to;
int next;
int val;
}edge[M];
int head[N],dis[N];
struct limit
{
int p,a,b;
}l[M];
//f[i]=max(c(1,i),f[j]+k+c(j+1,i));
void init()
{
memset(head,-1,sizeof(head));
cnt=1;
}
void edgeadd(int from,int to,int val)
{
edge[cnt].to=to;
edge[cnt].val=val;
edge[cnt].next=head[from];
head[from]=cnt++;
}
int cost(int le,int ri)
{
memset(can,0,sizeof(can));
for(int i=1;i<=d;i++)
{
if(max(le,l[i].a)<=min(ri,l[i].b))can[l[i].p]=1;
}
memset(dis,0x3f,sizeof(dis));
memset(v,0,sizeof(v));
queue<int>q;
q.push(1);
v[1]=1;
dis[1]=0;
while(!q.empty())
{
int u=q.front();
q.pop();
v[u]=0;
for(int i=head[u];i!=-1;i=edge[i].next)
{
int to=edge[i].to;
if(can[to])continue;
if(dis[u]+edge[i].val<dis[to])
{
dis[to]=dis[u]+edge[i].val;
if(!v[to])
{
q.push(to);
v[to]=1;
}
}
}
}
if(dis[m]==INF)return INF;
return dis[m]*(ri-le+1);
}
int main()
{
init();
scanf("%d%d%d%d",&n,&m,&K,&e);
for(int i=1;i<=e;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
edgeadd(x,y,z);
edgeadd(y,x,z);
}
scanf("%d",&d);
for(int i=1;i<=d;i++)scanf("%d%d%d",&l[i].p,&l[i].a,&l[i].b);
for(int i=1;i<=n;i++)
{
f[i]=cost(1,i);
for(int j=1;j<i;j++)
{
f[i]=min(f[i],f[j]+K+cost(j+1,i));
}
}
printf("%d\n",f[n]);
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
BZOJ 1003 [ZJOI2006]物流运输trans SPFA+DP
标签:
原文地址:http://blog.csdn.net/wzq_qwq/article/details/46754775