QOJ.ac

QOJ

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

#10641. Road Renovation [A]

Statistics

Most roads in Byteland are in a deplorable state. The King of Byteland, yielding to the numerous requests of his subjects, has decided to renovate some of the roads. There are $n$ cities in Byteland, numbered from 1 to $n$. Some pairs of cities are connected by one-way roads. The chief builder of Byteland has selected $m$ roads that he believes are suitable for renovation. For each of these roads, he has estimated the cost of its repair.

The King wants every citizen of Byteland to personally feel the improvement in road quality. He has assumed that the residents of any city will be satisfied if it is possible to enter their city and leave their city using at least one renovated road. The repairs must be planned so that their total cost is as low as possible. Creating a road renovation plan that meets the King's requirements has fallen to you.

Input

The first line of the input contains two integers $n$ and $m$ ($2 \le n \le 300$, $1 \le m \le n^{2}$) specifying the number of cities in Byteland and the number of one-way roads suitable for renovation. The next $m$ lines of the input contain three integers $x$, $y$, and $k$ ($1 \le x, y \le n$, $0 \le k \le 10^{5}$), meaning that renovating the road leading from city $x$ to city $y$ costs $k$ bytalars. Each ordered pair $x, y$ will appear in the input at most once. Note that there may be a road starting and ending in the same city.

Output

The first and only line of the output should contain a single integer specifying the minimum possible cost of carrying out the renovation according to the King's requirements, or the word NIE if it is not possible to prepare a plan that meets the King's requirements.

Examples

Input 1

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

Output 1

16

Input 2

4 4
1 2 5
2 3 4
3 1 8
2 4 7

Output 2

NIE

Discussions

About Discussions

The discussion section is only for posting: 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.
  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.