F.A.Qs Home ProblemSet Status Ranklist Contest LoginRegister
大视野在线测评-欢迎您
[ New Thread ]
Problem 1003 >> ert
xgcxgc @ 2016-04-06 13:42:29
[ Quote ] [ Edit ] [ Delete ] 1#
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
struct node
{
int x,y,d,next;
}a[110000]; int len,last[110];
void ins(int x,int y,int d)
{
len++;
a[len].x=x;a[len].y=y;a[len].d=d;
a[len].next=last[x];last[x]=len;
}
int list[110],tail,head;
int g[110][110],fl[110][110];
int dis[110],f[110];
int n,m,C;
int spfa(int st,int ed)
{
for(int i=1;i<=m;i++) dis[i]=999999;
head=1,tail=2;
list[1]=1;dis[1]=0;
while(head!=tail)
{
int x=list[head];
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if((fl[y][ed]-fl[y][st-1]==0) && (dis[y]>dis[x]+a[k].d))
{
dis[y]=dis[x]+a[k].d;
list[tail++]=y;if(tail==m+1) tail=1;
}
}
head++;if(head==m+1) head=1;
}
return dis[m];
}
int main()
{
int e,x,y,d;
scanf("%d%d%d%d",&n,&m,&C,&e);
memset(g,0,sizeof(g));
for(int i=1;i<=e;i++)
{
scanf("%d%d%d",&x,&y,&d);
if((g[x][y]==0)||(g[x][y]>d)) g[x][y]=g[y][x]=d;
}
len=0;memset(last,0,sizeof(last));
for(int i=1;i<=m;i++)
for(int j=i+1;j<=m;j++)
if(g[i][j]>0)
{
ins(i,j,g[i][j]);
ins(j,i,g[i][j]);
}
memset(fl,0,sizeof(fl));
scanf("%d",&d);
for(int i=1;i<=d;i++)
{
scanf("%d%d%d",&e,&x,&y);
for(int j=x;j<=y;j++) fl[e][j]=1;
}
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
fl[i][j]=fl[i][j]+fl[i][j-1];
f[0]=0;
for(int i=1;i<=n;i++)
{
f[i]=999999;
for(int j=1;j<=i;j++)
{
int t=spfa(j,i);
if(f[i]>f[j-1]+t*(i-j+1)+C) f[i]=f[j-1]+t*(i-j+1)+C;
}
}
printf("%d\n",f[n]-C);
return 0;
}
suxxsfe @ 2020-03-23 17:09:14
[ Quote ] [ Edit ] [ Delete ] 2#
???
[Top] [Previous Page] [Next Page]

HOME Back