DMOPC '16 Contest 4 P5 - Migrant Mascot

View as PDF

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

After indulging in one of her guilty pleasures for some time, Molly tears herself away from the booth. She begins moving along with the large crowds of the carnival and hopes this will lead to one of the fabled carnival attractions. After some time, Molly notices a busy intersection in front of her. There were no traces of the carnival to be seen…

The city in which Molly lives consists of undirected (relevant) roads and tourist traps attractions numbered from to , with being the carnival.

Molly exhibits a preference for certain types of roads over others and thus assigned each road with a preference value . The higher this value is, the better the road will be for Molly to traverse. With many paths leading away from the carnival to choose from, Molly will only remember a path by the lowest preference value of the roads which comprise it.

Molly would like to know the best possible value of any path leading from the carnival to a specific tourist attraction.

Since Molly cannot decide which of the tourist attractions in her city to visit next, she has enlisted your help.

Write a program to determine the desired value for each of the tourist attractions to help Molly!

Note: A path is a series of roads joining any two (different) attractions.

Input Specification

Line : Two space separated integers and , denoting the number of tourist attractions and relevant roads respectively.
Line : Three space separated integers , denoting an edge between tourist attractions and with a weight of .

Output Specification

Your program should output lines, the of which represents the best possible value of the path leading from the carnival to the attraction.

Constraints

It is possible to reach every attraction from every other attraction.

Sample Input

3 3
1 2 3
2 3 3
1 3 7

Sample Output

0
3
7

Explanation

Because Molly was just at the Carnival, she is no longer interested in spending time there. As a result, the value for # is (always) .

The lowest preference value of either path leading to attraction # is .

There are two paths leading from the carnival (#) to attraction #: and , with respective values (as Molly recalls) of (the only preference value of the path) and .

• commented on June 27, 2020, 9:05 p.m.

What is the issue with my code? It works with CCC '03 S5 Trucking trouble but does not work with this question

• commented on June 29, 2020, 2:59 p.m.

Your code is incorrect in some cases. You are simply checking if a weight of an edge is bigger than the previous answer stored in your distance array, however it does not reflect the intention of the problem, which defines the weight of a path is the minimum of all edges along that path, and you need to find such a maximum path, not just one edge.

• commented on June 29, 2020, 3:54 p.m.

So, I fixed the issue of minimum now, by keeping a visited array and if a node is already visited I update it with min() of all roads within a path to prev node and maximum of that value, its initial distance. It was able to pass batch #2 but fails in batch #3

• commented on June 29, 2020, 4:01 p.m. edit 3

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on Oct. 20, 2019, 6:52 p.m. edited

I'm not sure if I'm understanding the problem correctly but shouldn't the answer for the sample input be 0 3 3?

Edit: I realized that Molly goes to the path with the largest preference value. Thanks injust!

• commented on Oct. 20, 2019, 7:39 p.m.

is the maximum preference value of all paths from to .

The preference value of a path is the lowest preference value of the roads that make up said path.

• commented on May 26, 2019, 7:13 p.m. edited

Raise memory limit for python?