|
|
вернуться в форумFor the people who WA TEST#5 #include <stdio.h> int main() { long i,a[2][100]={0},n,k,x,y,j,c=0,next; long max=2147483647; char ch; scanf("%ld*",&n); for (i=1;i<=n;i++) { scanf("%ld*",&k); for (j=1;j<=k;j++) a[c][j]=2147483647; next=(c+1)%2; for (j=1;j<=k;j++) { scanf("%ld",&x); while (x!=0) { scanf("%ld*",&y); if (a[c][j]>a[next][x]+y) a[c][j]=a[next][x]+y; scanf("%ld",&x); } } if (i!=n) { c=next; scanf("%c*",&ch); } } for (i=1;i<=k;i++) if (a[c][i]<max) max=a[c][i]; printf("%ld",max); return 0; }
Initial value0-------> Initial value2147483647 I think TEST#5 must have a node which min value is 0. Re: For the people who WA TEST#5 in TEST#5 is a Nth level planet which can not go with the Ivanushka's planet Re: For the people who WA TEST#5 #include "iostream" using namespace std; void main () { long n,lay,from,fee; long i=0; long j; long arr[35]; long arr2[35]; long* one; long* two; long* help; char c; for (i=0;i<35;i++) { arr2[i]=0; arr[i]=0; }; one=arr; two=arr2; cin>>n; for (i=0;i<n;i++) { cin>>lay; for (j=0;j<lay;j++) { cin>>from; if (from==0) { continue;} cin>>fee; two[j+1]=one[from]+fee; while(2>1) { cin>>from; if (from==0) { break;} cin>>fee; if (two[j+1]>(one[from]+fee)) { two[j+1]=one[from]+fee; }; }; }; if (i!=n-1) { help=one; one=two; two=help; cin>>c; }; }; long m; m=two[1]; for (j=1;j<lay;j++) if (m>two[j+1]) m=two[j+1]; cout<<m; } |
|
|