 # PLAG04 - Editorial

PRACTICE
Editorialist: Avishake Maji

MEDIUM

Graphs

# PROBLEM:

Chef and his team after working for making years finally succeeded in building up a plagiarism detector. But when Chef is taking a nap the warning alarm suddenly rings. Since Chef is the only one who is near to the base where the plagiarism detector is fitted so he has to fix the problem before their detector destroys.

There are different paths from chef’s base to the target base but chef has to take the shortest path and fix the problem before the timer T(min)T(min) goes to 00. Chef knows the map of the base and the distance between two consecutive bases. Chef needs your help to find whether he will reach in time or not. If he is able to reach in time print “Successful” else print “Unsuccessful”.

There are N number of bases. Chef lives in base 11 and he has to reach the base N. The speed at which chef’s run is given in S(meter/min)S(meter/min). Remember chef runs at a uniform speed throughout. U and V denote any pair of bases and W(meter)W(meter) is the distance between U and VV.

# EXPLANATION:

Here in this problem, we have first find the shortest distance from Base 1 to Base N i.e target base. We can use Dijkstra’s algorithm which solves the single-source shortest path problem. After
finding the shortest path, we have to calculate time.

# SOLUTION:

``````#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll mindistance(bool *vis,ll *dist,ll n){
ll minval=INT_MAX;
ll min_ind;
for(ll i=0;i<n;i++){
if(dist[i]<=minval&&vis[i]==false){
minval=dist[i];
min_ind=i;
}
}
return min_ind;
}
ll *dist=new ll[n];
bool *visited=new bool[n];
for(ll i=0;i<n;i++)
{
visited[i]=false;
dist[i]=INT_MAX;
}
dist=0;
for(ll i=0;i<n-1;i++){
ll u=mindistance(visited,dist,n);
visited[u]=true;
for(int j=0;j<n;j++){
}
}
}
return dist[n-1];
}
int main(){
ll n,e,t,speed;
cin>>n>>e>>t>>speed;
ll u,v,w;
for(ll i=0;i<e;i++)
{
cin>>u>>v>>w;