10099 - The Tourist Guide

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>

using namespace std;
int mat[101][101];

int koyta_city,koyta_road,shuru,shesh,i,j,k,a,b,cost,trips,test=0;

double koyjon_tourist,c;

void Floyd()
{
    for(k=1;k<=koyta_city;k++)
    {
        for(i=1;i<=koyta_city;i++)
        {
            for(j=1;j<=koyta_city;j++)
            {
                mat[i][j]=max(mat[i][j],min(mat[i][k],mat[k][j]));
            }
        }
    }

}

int main()
{
    while(cin>>koyta_city>>koyta_road)
    {
        if(koyta_city==0 && koyta_road==0)
        {
            break;
        }

        for(i=1;i<=koyta_road;i++)
        {
            cin>>a>>b>>cost;
            mat[a][b]=cost;
            mat[b][a]=cost;
        }

        Floyd();

        cin>>shuru>>shesh>>koyjon_tourist;

        c=mat[shuru][shesh]-1;

        trips = ceil(koyjon_tourist/c);


        cout<<"Scenario #"<<++test<<endl;
        cout<<"Minimum Number of Trips = "<<trips<<endl<<endl;
        memset(mat,0,sizeof(mat));

    }
    return 0;
}

0 comments: (+add yours?)