0

This is my code for MICEMAZE. Write a program that, given a description of the maze and the time limit, predicts the number of mice that will exit the maze. Assume that there are no bottlenecks is the maze, i.e. that all cells have room for an arbitrary number of mice.

#include <iostream>
#include <cstring>
#include <climits>
using namespace std;
int n,e,t,m;
int d[101][101];
int dis[101];
bool vis[101];
void djk()
{
    memset(vis,false,sizeof vis);

    for(int i=0;i<n;i++)
    {
        dis[i]=300000000;


    }
     dis[e]=0;
    for(int i=0;i<n;i++)
    {
        int mi = INT_MAX, u;

   for (int v = 0; v < n; v++)
     if (vis[v] == false && dis[v] <= mi)
         mi = dis[v], u = v;
        vis[u]=true;
            for(int j=0;j<n;j++)
            {
                if(d[u][j]!=0 && dis[j]!=INT_MAX && vis[j]==false &&     dis[j]>dis[u]+d[u][j])
                    dis[j]=dis[u]+d[u][j];
            }
    }
}

int main()
{
    cin>>n>>e>>t>>m;
    memset(d,0,sizeof d);
    e--;
    for(int i=0;i<m;i++)
    {
        int x,y,s;
        cin>>x>>y>>s;
        d[x-1][y-1]=s;
    }
    int cnt=0;
    djk();
    for(int i=0;i<n;i++)
    {
        //cout<<dis[i]<<endl;
        if(dis[i]<=t) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}
Daniel Cassidy
  • 24,676
  • 5
  • 41
  • 54
  • Please be specific about the problem you're trying to solve. Is there something going wrong with your code that you need help with, or are you just looking for a code review. As a new user, I encourage you to read this post: http://stackoverflow.com/help/mcve – Mike Zavarello Jul 13 '16 at 18:32
  • If you can't find where your code is failing I suggest you look at http://spojtoolkit.com/test/MICEMAZE. Try creating smaller input and compare the expected output from the toolkit and what your code produces. It'll be frustrating but its definitely worth it :) Or try the already available test cases http://spojtoolkit.com/history/MICEMAZE – thebenman Sep 13 '16 at 07:01

0 Answers0