please provide a cpp code for the problem
You need to travel from city to city N across a land divided into N cities
connected by M undirected roads. Each road i i M between cities Ui and Vi
has certain constraints, characterized by Ai entities each with Bi resistance points. The travel time to cross this road at time t depends on these constraints: it takes Ait Bi time units to overcome the entities and move on to city Vi where the division is done using integer division. You can start your journey at time or any integer time unit thereafter, and you can wait at any city for any integer amount of time. The goal is to minimize the overall journey time. If it is not possible to reach city N the result should be The task is to find the minimum time required to complete your journey.
Input :
First line of input consists of N and M N M
The next M lines contain the description of the undirected roads.
The i th i M line consists of Ui Vi Bi Ai Ui Vi N Ai Bi
Output :
Print the minimum time possible according to the problem statement.
Examples
Input :
Output :
input:
Output :
Hint :
ty tx Aitx Bi
tx is the time when you depart from city x for city y
a code was provided for the problem but it is totally wrong and doesnt run for the testcases given, I will give the code for reference but please provide a code for the problem that satisfies the given examples
Include necessary libraries
#include
using namespace std;
Define types for ease of use
#define ll long long
#define pll pair
#define ppll pair
#define INF e
Initialize the adjacency list and the distance vector
vector adj;
vector dist;
Function to implement Dijkstra's algorithm
void dijkstraint start
Initialize the priority queue with the start city
priorityqueue, greater pq;
pqpush start;
diststart;
While there are cities in the queue
whilepqempty
Get the city with the shortest distance
ll city pqtopsecond;
ll time pqtopfirst;
pqpop;
If the current shortest distance is not equal to the calculated distance, skip this city
iftime distcity continue;
Update the distances for each neighboring city
forauto &road : adjcity
ll nextCity road.first;
ll A road.second.first;
ll B road.second.second;
Binary search to find the minimum time to cross the road
ll low high e;
whilelow high
ll mid low high;
ifmid B A mid mid time B
high mid;
else
low mid ;
Calculate the next time
ll nextTime low B A low low;
If the calculated next time is less than the current shortest distance to the next city, update it
ifnextTime distnextCity
distnextCity nextTime;
pqpushnextTime nextCity;
Main function
int main
Speed up inputoutput operations
iosbase::syncwithstdiofalse;
cin.tieNULL;
Read the number of cities and roads
int N M;
cin N M;
Resize the adjacency list and the distance vector
adj.resizeN;
dist.assignN INF;
Read the details of each road
forint i ; i M; i
int U V A B;
cin U V A B;
adjUpushbackVA B;
adjVpushbackUA B;
Call Dijkstra's algorithm starting from city
dijkstra;
If it's not possible to reach city N print
Otherwise, print the minimum time required
ifdistN INF
cout
;
else
cout distN
;
return ;