Description
Input
Output
Sample Input
5 1 0 1 1 2 0 2 3 3 1 1 1 4 100 0 1 0 1
Sample Output
2
水题,就是处理输入有点麻烦;
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int M = 15;
const int INF = 0x3f3f3f;
struct node{
int from,to,val;
int next;
};
int head[M];
int dis[M][M],map[M];
int vis[M];
node edge[2*M];
int m,n,a,b,c,d,ans;
void init(){
memset(vis,0,sizeof(vis));
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(i == j) dis[i][j] = dis[j][i] = 0;
else dis[i][j] = dis[j][i] = INF;
}
}
}
void floyd(int n){
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
for(int k=0; k<n; k++){
if(dis[i][k]+dis[k][j]<dis[i][j]){
dis[i][j] = dis[i][k]+dis[k][j];
}
}
}
}
}
int main()
{
while(~scanf("%d",&n)){
init();
for(int i=0; i<n; i++){
scanf("%d%d",&a,&b);
vis[i] = b;
for(int j=0; j<a; j++){
scanf("%d%d",&c,&d);
if(dis[i][c]>d)
dis[i][c] = d;
}
}
floyd(n);
int min = INF;
for(int i=0; i<n; i++){
if(min>dis[0][i]&&vis[i]){
min = dis[0][i];
}
}
printf("%d\n",min);
}
return 0;
}