#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 5000
typedef struct {
int v, w;
}node;
node data[1000];
int step=0,vis[1000],cost[1000];
int a[2]={-1,1};
int N,V;
int dfs(int v)
{
vis[v]=0;
for(int i=0; i<2; i++)
if(!vis[v+a[i]])
{
step++;
for(i=0; i<N; i++)
if(v+a[i]==data[i].v)
cost[v+a[i]]=step*data[i].w;
vis[v+a[i]]==1;
}
}
int cap(int v)
{
memset(cost, 0, sizeof(cost));
memset(vis, 0, sizeof(vis));
vis[v]==1;
for(int i=0; i<N; i++)
if(!vis[data[i].v]) dfs(data[i].v);
}
int main()
{
while(scanf("%d",&N)!= EOF)
{
scanf("%d",&V);
for(int i=0; i<N; i++)
scanf("%d %d",&data[i].v, &data[i].w);
cap(V);
for(int i=0; i<100; i++)
printf("%d ",cost[i]);
}
system("pause");
return 0;
}
点击打开链接