QOJ.ac

QOJ

时间限制: 3.0 s 内存限制: 256 MB 总分: 100

#15906. 王国

统计

有几个王国陷入了严重的财政危机。多年来,它们一直在秘密地互相借贷。现在,随着债务的曝光,崩溃已不可避免……

共有 $n$ 个王国。对于每一对王国 $(A, B)$,王国 $A$ 欠王国 $B$ 的黄金数量用整数 $d_{AB}$ 表示(假设 $d_{BA} = -d_{AB}$)。如果一个王国的余额为负(即需要支付的金额超过了它能收回的金额),它可能会破产。破产会消除该王国所有的债务(无论是正债还是负债),就好像该王国不复存在了一样。随后,下一个王国可能会破产,以此类推,直到所有剩余的王国都达到财政稳定。

根据破产顺序的不同,可能会出现不同的情况——特别是,有时可能只会剩下一个王国。请确定对于每个王国,它是否有可能成为唯一的幸存者。

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是各测试用例的描述:

每个测试用例的描述以一行包含王国数量 $n$ 开始,其中 $1 \leqslant n \leqslant 20$。随后有 $n$ 行,每行包含 $n$ 个用空格分隔的数字。第 $i$ 行的第 $j$ 个数字表示第 $i$ 个王国欠第 $j$ 个王国的黄金数量 $d_{ij}$。你可以假设对于所有 $1 \leqslant i, j \leqslant n$,都有 $d_{ii} = 0$ 且 $d_{ij} = -d_{ji}$。此外,对于所有可能的 $i, j$,满足 $|d_{ij}| \leqslant 10^6$。

输出格式

按输入中出现的顺序打印每个测试用例的答案。对于每个测试用例,打印一行,包含所有可能成为唯一幸存者的王国的索引,按升序排列。如果没有这样的王国,则打印数字 0。

样例

输入 1

1
3
0 -3 1
3 0 -2
-1 2 0

输出 1

1 3

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.