#include<stdio.h>
#include<cstring>
#define INF 0x3f3f3f3f
int grid[102][102],dist[102],d[102],in[102],ans=INF,n,m;
structnode
{
int P,L,X;
}g[102];
int Dijkstra()
{
int i,k,num=1,minc=INF,min;
memset (dist,0x3f,sizeof(dist));
memset(d,0,sizeof(d));
dist[1]=0;
while (num++<n)
{
min=INF;
for(i=1;i<=n;i++)
if(!d[i] && dist[i]<min)
{k=i;min=dist[i];}
d[k]=1;
for (i=1;i<=n;i++)
if(in[i] && dist[i]>dist[k]+grid[k][i])
dist[i]=dist[k]+grid[k][i];
}
for(i=1;i<=n;i++)
{
dist[i]+=g[i].P;
if(minc>dist[i])
minc=dist[i];
}
return minc;
}
int main()
{
int i,j,k,b,x,y,t,p;
scanf("%d%d",&m,&n);
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
grid[i][j]=i==j?0:INF;
for (i=1;i<=n;i++)
{
scanf("%d%d%d",&g[i].P,&g[i].L,&g[i].X);
t=g[i].X;
while (t--)
{
scanf("%d%d",&k,&b);
grid[i][k]=b;
}
}
for(x=g[1].L-m;x<=g[1].L;x++)
{
y=x+m;
memset(in,0,sizeof(in));
for(i=1;i<=n;i++)
if (g[i].L>=x && g[i].L<=y)
in[i]=1;
p=Dijkstra();
if(ans>p)
ans=p;
}
printf("%d\n",ans);
return 0;
}
转载于:https://www.cnblogs.com/You-Change/p/3472113.html