View Code of Problem 14

#include<stdio.h>

int main(){
    int n, t, a, b, value, w, e, c, d, length;
    int i = 0;
    int map[100][100]={{0}};
    while(scanf("%d%d", &n, &t) && (n || t) && ++i){
        while(t--){
            scanf("%d%d%d", &a, &b, &value);
            if(!map[a][b] || (map[a][b] && map[a][b] > value))
                map[a][b] = value;
        }
        scanf("%d%d", &w, &e);
        length = 0;
        while(w--){
            scanf("%d%d", &c, &d);
            if(d == e)
                break;
            length += map[c][d];
        }
        printf("Case #%d: %d\n", i, length);
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 14