QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#581. Bridges

統計

San Bytecisco is a beautifully situated coastal town. It consists of $n$ small, yet densely populated islands, numbered from $1$ to $n$. Certain islands are connected with bridges, used for (bidirectional) road traffic. Each pair of islands can be connected with at most one bridge. The islands are connected in such a way that every island can be reached from every other by using the bridges only.

Byteasar and Bytie are going for a bike trip in San Bytecisco. The will start their ride at the island no. 1. They intend to visit every island, while passing along every bridge once and ending the trip where it began, i.e., the island no. 1. Being quite seasoned riders, they expect some serious trouble from... the wind! After all, it is very windy along the coast, and especially so on the bridges between the islands. Obviously, depending on its speed and direction, the wind makes it hard to cross the bridge in different extent for either direction. For simplicity we will assume for every bridge and direction of crossing, the opposing wind speed is constant.

Help Byteasar and Bytie to find a route as they desire that will in addition be the least tiresome. Byteasar and Bytie agreed on the maximum opposing wind speed as a measure of a route's tiresomeness.

Input

In the first line of the standard input there are two integers separated by a single space: $n$ and $m$ ($2 ≤ n ≤ 1\,000$, $1 ≤ m ≤ 2\,000$), denoting the number of islands and the number of bridges in San Bytecisco respectively. The islands are numbered from $1$ to $n$, while the bridges from $1$ to $m$. The following $m$ lines specify the bridges. The line no. $(i+1)$ contains four integers $a_i$, $b_i$, $l_i$, $p_i$ ($1 ≤ a_i,b_i ≤ n$, ai≠bi, $1 ≤ l_i,p_i ≤ 1\,000$), separated by single spaces. These denote that the bridge no. $i$ connects the islands no. $a_i$ and $b_i$. The opposing wind speeds are $l_i$ when one goes moves from $a_i$ to $b_i$, and $p_i$ if one goes from $b_i$ to $a_i$.

Output

If there is no route satisfying the requirements of the daring two riders, the first and only line of the standard output should hold the word NIE (no in Polish). Otherwise, the output should have two lines, specifying the least tiresome route over San Bytecisco. The first line should hold the maximum opposing wind speed for that route, i.e., the number we wish to minimize. The second line should hold m integers, separated by single spaces, giving the numbers of successive bridges one crosses on the least tiresome route.

Should there be more than one least tiresome route, your program can pick one arbitrarily.

Example

Input

4 4
1 2 2 4
2 3 3 4
3 4 4 4
4 1 5 4

Output

4
4 3 2 1

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.