utilized exceptionally cutting edge innovation to construct the cannons, the cannons turn each second. As such, if the I-th gun is pointing towards the city x at some second, it will focus on the city (x+1)modn at the following second.    As their name proposes, transport cannons are

Operations Research : Applications and Algorithms
4th Edition
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Wayne L. Winston
Chapter19: Probabilistic Dynamic Programming
Section: Chapter Questions
Problem 10RP
icon
Related questions
Question

Correct answer will be upvoted else downvoted.

 

AaParsa utilized exceptionally cutting edge innovation to construct the cannons, the cannons turn each second. As such, if the I-th gun is pointing towards the city x at some second, it will focus on the city (x+1)modn at the following second. 

 

As their name proposes, transport cannons are for transportation, explicitly for human vehicle. On the off chance that you utilize the I-th cannon to dispatch yourself towards the city that it's at present pointing at, you'll be airborne for ci seconds prior to arriving at your objective. 

 

On the off chance that you actually don't get it, utilizing the I-th gun at the s-th second (utilizing which is just conceivable in case you are at present in the city simulated intelligence) will shoot you to the city (bi+s)modn and you'll land in there after ci seconds (so you'll be there in the (s+ci)- th second). Additionally note the gun that you at first dispatched from will pivot each second however you clearly will not alter course while you are airborne. 

 

AaParsa needs to utilize the guns for going between Shaazzzland's urban areas in his fabulous arrangement, and he can begin going at second 0. For him to completely use them, he has to know the base number of seconds needed to arrive at city u from city v utilizing the guns for each pair of urban areas (u,v). 

 

Note that AaParsa can remain in a city however long he needs. 

 

Input 

 

The principal line contains two integers n and m (2≤n≤600,n≤m≤n2) — the number of urban areas and guns correspondingly. 

 

The I-th line of the accompanying m lines contains three integers computer based intelligence, bi and ci (0≤ai,bi≤n−1,1≤ci≤109), signifying the gun in the city artificial intelligence, which is at first highlighting bi and going by which requires ci seconds. 

 

It is ensured that every one of the n urban areas has something like one vehicle gun planted inside it, and that no two guns from a similar city are at first pointing at a similar city (that is, all sets (ai,bi) are unmistakable). 

 

Output 

 

Print n lines, each line ought to contain n integers. 

The j-th integer in the I-th line ought to be equivalent to the base time needed to arrive at city j from city I.

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole