QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 64 MB Points totaux : 10

#11032. 研究 [A]

Statistiques

拜特兰大学(BU)的计算机科学课程包含 $n$ 个等级。每个等级相当于一个学期,但等级的数量可能少于或多于传统计算机科学课程的学期数。在学习期间,每位学生都可以向系主任提交不同的申请。这些申请对学生的职业生涯有重大影响。特别是,申请可能会导致学习等级的变更。提交申请会对学生的预算产生财务影响——既可能是盈利(奖学金),也可能是亏损(参加额外课程的费用等)。

拜特曼(Byteman)是 BU 一名懒惰但非常聪明的学生。过去几年里,他一直在收集其他学生提交的不同申请的数据。对于每一项申请,拜特曼都知道该申请如何影响学习等级以及学生的预算。拜特曼并不关心是否能快速毕业。他唯一关心的是最大化他的收入。

实现无限收入的保证是以下情况:学生可以从某个等级开始学习,然后提交一系列申请,使得最后他回到初始学习等级,同时赚取一定数量的正数拜特币。拜特曼是一个非常有耐心的人——他可以提交许多申请。天哪……只要这个行为能带来正收益,他甚至可以多次提交相同的申请。拜特曼假设系主任的行为是确定性的,这意味着对同一申请的答复总是相同的。

请编写一个程序:

  • 从标准输入读取所有可能申请的描述,
  • 确定 BU 中所有可能导致无限收入的学习等级,
  • 将结果写入标准输出。

输入格式

输入的第一行包含两个整数 $n$ 和 $m$ ($2 \le n \le 300$, $1 \le m \le n(n - 1)$),由一个空格分隔,分别表示 BU 的等级数量和要分析的申请数量。接下来的 $m$ 行包含申请的描述。每一行包含三个整数 $a_{i}$、$b_{i}$ 和 $c_{i}$ ($1 \le a_{i}, b_{i} \le n$, $a_{i} \neq b_{i}$, $-10^{9} \le c_{i} \le 10^{9}$),由空格分隔,含义如下:学生提交申请时所处的学习等级、申请经系主任审议后学生被转入的学习等级,以及与该申请相关的费用(正值代表学生的利润,负值代表损失)。没有任何一对 $(a_{i}, b_{i})$ 会出现超过一次,但 $(a_{i}, b_{i})$ 和 $(b_{i}, a_{i})$ 可能同时出现在输入中。

输出格式

输出的第一行应包含一个整数 $k$,表示拜特曼可以开始学习以获得无限收入的不同学习等级的数量。第二行应包含 $k$ 个范围在 $\{1, \ldots, n\}$ 内的整数,由空格分隔,表示拜特曼感兴趣的所有学习等级。数字应按升序排列。

样例

输入 1

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

输出 1

5
4 5 6 7 8

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.