17 Mar 2013

Bonus_SOLVED


/*

CODECHEF
PROBLEM CODE : ACMKANPB

*/

#include <stdio.h>
 
int main()
{
int fall, i, c, n, m, l, t, j, x[4][10100];

for(scanf("%d",&fall); fall--;)
{
for(i=!!scanf("%d %d %d",&n,&m,&l); i<=m; x[0][i++]=l);
for(i=-1; ++i<m; scanf("%d %d %d",&x[1][i],&x[2][i],&x[3][i]));
for(j=!(c=1); c&&j<n; j++)
for(i=-!(c=0); ++i<m; x[0][x[1][i]]=(x[0][x[1][i]]<x[0][x[2][i]]+x[3][i])?x[0][x[2][i]]+x[3][i]+(c=1)*0:x[0][x[1][i]]);
for(i=0; x[0][x[1][i]]-x[0][x[2][i]]>=x[3][i]&&i<m; i++);
if(i<m)
puts("Inconsistent analysis.");
else
{
for(i=!(t=0); i<=n; t+=x[0][i++]);
printf("%d\n",t);

for(i=1; i<=n; printf("%d ",x[0][i++]));
puts("");
}
}
return 0;
}

Categories: , , ,

0 comments:

Post a Comment

Copyright © UPgradeCODING | Powered by Blogger