View Code of Problem 14

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n,t,a,b,value,w,e,c,d;
    int k=1;
    while(cin>>n>>t)
    {
        if(t==0&&n==0)
        {
            return 0;
        }
        int edge[n][n];
        memset(edge,1,sizeof (edge));

        while(t--)
        {
            cin>>a>>b>>value;
            if(edge[a][b]>value)
            {
                edge[a][b]=value;
            }
        }

        cin>>w>>e;
        int sum=0;
        int flag=1;
        while(w--)
        {
            cin>>c>>d;
            if(c<d && flag==1)
            {
                sum=sum+edge[c][d];
                edge[c][d]=0;
            }
            if(d==e)
            {
                flag=0;
            }

        }
        cout<<"Case #"<<k++<<": "<<sum<<endl;
    }

}

Double click to view unformatted code.


Back to problem 14