182955 ylwh URAL 1210 Accepted 108 KB 31 ms C 712 B 2011-08-12 14:39:20
#include <stdio.h>
#include <string.h>
#define N 31
#define MAX 200000000
int main()
{
int n, temp[N], s[N], i, j, k, pre, dis, ans;
char ch;
while(scanf("%d", &n) != EOF)
{
s[0] = 1;
s[1] = 0;
for(i=1; i<=n; i++)
{
scanf("%d", &k);
temp[0] = k;
for(j=1; j<=k; j++)
temp[j] = MAX;
for(j=1; j<=k; j++)
{
while( scanf("%d", &pre), pre)
{
scanf("%d", &dis);
if(temp[j] > s[pre] + dis)
temp[j] = s[pre] + dis;
}
}
if(i!=n) scanf(" %c", &ch);
for(j=0; j<=temp[0]; j++)
s[j] = temp[j];
}
ans = s[1];
for(i=2; i<=s[0]; i++)
if(s[i] < ans)
ans = s[i];
printf("%d\n", ans);
}
return 0;
}
睡了一觉~~,想出来了~~~(话说刚开始想的是最短路。。。
URAL 1210 Kind Spirits
最新推荐文章于 2022-02-25 21:57:21 发布