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 to 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

For all subtasks:

Subtask | Points | |
---|---|---|

1 | 20 | |

2 | 30 | |

3 | 50 |

- 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 .

## Comments

XD

Please don't post solution code in the comments. It disrupts other users who are trying to solve the problem

Raise memory limit for python?

WA in batch 3?I implemented my solution for CCC '03 S5 Trucking Troubles, which AC'd there, but I get WA in test case 1 of batch 3. Is this due to some sort of edge case? EDIT: Resolved

Why am i getting MLE for the first test case it is using 171 mb? even though n is in between 1 and 15.

PyPy sacrifices memory for speed, and as such uses around 3 times as much memory as CPython.

Submitted same code in python 2.7 uses more memory than in pypy, still MLE. :(

I ran into a similar problem when using python. Considering this problem was designed around being solvable in c++, the author must have not taken into account how slow python is. Who knows though, it might just be my complexity is too high.