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;
}