#include <stdio.h>
#include <stdlib.h>
typedef struct edge{
int veradj;
int cost;
struct edge*link;
}edge;
typedef struct head{
int vername;
edge*adjacent;
}head;
edge*creatnode(edge*p,int c,int a){//创建顶点
p=(edge*)malloc(sizeof(edge));
p->veradj=c;
p->cost=a;
p->link=NULL;
return p;
}
head*build(int n,head*headt[]){//创建邻接图
int i=0;
for(i=0;i<n;i++)
{headt[i]=(head*)malloc(sizeof(head));
headt[i]->vername=i;
headt[i]->adjacent=NULL;}
int c;int cost;
edge*p,*q;
for(i=0;i<n;i++)
{
scanf("%d%d",&c,&cost);
while(c!=-1){
p=creatnode(p,c,cost);
if(headt[i]->adjacent==NULL)
{headt[i]->adjacent=p;
q=p;}
else{
&