Go to diff to previous submission
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> int conn[2000][2000]; int pipes[2000]; int nodes; int count(int node, int from) { int i, inputc= 1000000000, childc = 0; //printf("count node %d from %d\n", node, from); if (pipes[node]==1 && from != -1) { //printf("leaf %d\n", node); return conn[node][from]; } for (i=1; i<nodes+1; i++) { if (i==from) { inputc = conn[node][i]; } else { //childc += conn[node][i]; if (conn[node][i] > 0) childc += count(i, node); } } //printf("node %d from %d input %d child %d\n", node, from, inputc, childc); if (childc == 0) return inputc; return childc > inputc ? inputc : childc; } int main(int argc, char **argv) { int rv, root, i, n1, n2, w; while (1) { if (rv != 2) break; for (i=0; i<nodes-1; i++) { conn[n1][n2] = w; conn[n2][n1] = w; pipes[n1]++; pipes[n2]++; } } return 0; }
--- c5.s708.cteam089.fr.c.0.fr.c +++ c5.s767.cteam089.fr.c.0.fr.c @@ -5,4 +5,5 @@ int conn[2000][2000]; +int pipes[2000]; int nodes; @@ -10,4 +11,8 @@ int i, inputc= 1000000000, childc = 0; //printf("count node %d from %d\n", node, from); + if (pipes[node]==1 && from != -1) { + //printf("leaf %d\n", node); + return conn[node][from]; + } for (i=1; i<nodes+1; i++) { if (i==from) { @@ -30,8 +35,11 @@ if (rv != 2) break; memset(conn, 0, sizeof(conn)); + memset(pipes, 0, sizeof(pipes)); for (i=0; i<nodes-1; i++) { scanf("%d%d%d", &n1, &n2, &w); conn[n1][n2] = w; conn[n2][n1] = w; + pipes[n1]++; + pipes[n2]++; } printf("%d\n", count(root, -1));