QOJ.ac

QOJ

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

#11032. Studies [A]

統計

Byteland University (BU) offers Computer Science studies consisting of $ n $ levels. Each level is an equivalence of semester, however the number of levels can be less or greater than the number of semesters at the classical CS studies program. Every student during his studies can submit different applications to the dean of the faculty. Those applications have a great impact on the student's career. In particular, applications can result in the change of level of the studies. Submitting an application can have financial impact on the student's budget - as well profitable (scholarships) as negative (charges for attending additional classes etc.).

Byteman is a lazy, but very smart student of BU. For the past years he has been collecting data about different applications that have been submitted by other students of BU. For each application, Byteman knows how the application influenced the level of studies as well as the budget of the student. Byteman doesn't care much about fast graduation. The only thing he cares about is maximizing his income.

A guarantee of infinite income is the following situation: student can start his studies from some level and then submit a sequence of applications in such a way that at the end he returns to the initial level of studies, earning at the same time some positive amount of bytedollars. Byteman is a very patient person - he can submit many applications. Gush... He can even submit the same application many times, as long as this action leads to some positive income. Byteman assumes that the dean behaves deterministically, which means that the answer to the same application is always the same.

Write a program which:

  • reads a description of all possible applications from the standard input,
  • determines all levels of studies at the BU, which can lead to infinite income,
  • writes the result to the standard output.

Input Format

The first line of the input contains two integers $ n $ and $ m $ ($2 ≤ n ≤ 300$, $1 ≤ m ≤ n(n - 1)$), separated with a single space and representing the number of levels at the BU and the number of applications to analyze. Following $ m $ lines contain description of applications. Each line contains three integers $ a_{i} $, $ b_{i} $ and $ c_{i} $ ($1 ≤ a_{i}, b_{i} ≤ n $, $ a_{i} ≠ b_{i} $, $-10^{9} ≤ c_{i} ≤ 10^{9}$), separated with single spaces and meaning: the level of studies student was at, when he submitted an application, the level of studies student got transferred to after application had been considered by the dean and costs associated with this application (positive value represents profit of the student, negative - loss). None of the pairs $(a_{i}, b_{i})$ occurs more than once, but both $(a_{i}, b_{i})$ and $(b_{i}, a_{i})$ can occur in one input.

Output Format

The first line of the output should contain one integer $ k $, representing the number of different levels of studies, from which Byteman can start his studies to obtain infinite income. The second line should contain $ k $ integers in the range $\{1, \ldots, n\}$, separated with single spaces and representing all levels of studies Byteman is interested in. Numbers should be listed in increasing order.

Example

Input

8 8
1 2 3
1 3 -3
5 4 4
6 5 -1
6 7 -1
7 8 5
8 6 2
4 8 -3

Output

5
4 5 6 7 8
problem_11032_1.png
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.