Wednesday, 30 September 2015

UVA 10099 - The Tourist Guide

///     Raihan Ruhin
///     CSE, Jahangirnagar University.
///     Dhaka-Bangladesh.
///     id: raihanruhin (topcoder / codeforces / codechef / uva / uvalive / spoj), 3235 (lightoj)
///     mail: raihanruhin@ (yahoo / gmail / facebook)
///     blog: ruhinraihan.blogspot.com

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

#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)

#define MOD 1000000007
#define MX 100010

int cost[102][102];

void FloydWarshallFlow(int n)
{
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                cost[i][j]=max(cost[i][j], min(cost[i][k], cost[k][j])); //modified
return;
}


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int tc, kk=1, n, m, u, v, w;
    string s;
    char ch;
    while(cin>>n>>m && n)
    {
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                cost[i][j]=0;
        while(m--)
        {
            cin>>u>>v>>w;
            cost[u][v]=w;
            cost[v][u]=w;
        }
        FloydWarshallFlow(n);
        cin>>u>>v>>w;
        cout<<"Scenario #"<<kk++<<"\n";
        //cout<<cost[u][v]<<endl;
        cout<<"Minimum Number of Trips = ";
        cout<< ceil((double)w/(double)(cost[u][v]-1))<<"\n\n";
    }
return 0;
}

No comments:

Post a Comment