2024 ICPC Asia Taichung Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams) |
---|
Finished |
In an interdisciplinary collaboration, an ecosystem scientist and a computer scientist join forces to analyze the structure of a complex ecosystem using computational methods. The ecosystem scientist models the ecosystem as a directed graph $$$D = (V, A)$$$, where each species is represented by a node $$$v \in V$$$, and each feeding relationship is represented as a directed edge $$$(x, y) \in A$$$ from prey $$$x$$$ to predator $$$y$$$. This graph structure allows them to simulate the flow of energy throughout the ecosystem from one species to another.
Two essential features of the ecosystem are defined:
Consider an ecosystem with $$$n = 4$$$ species and $$$m = 3$$$ feeding relationships:
The directed edges representing the feeding relationships are as follows:
Now, consider the set $$$S=\{3,4\}$$$ (Foxes and Hawks). There are no directed paths between Foxes (Node 3) and Hawks (Node 4); Foxes cannot reach Hawks, and Hawks cannot reach Foxes through any directed paths. Therefore, this set qualifies as an independent trophic group.
Examination of Species
Among these species, Rabbits have the smallest absolute difference of $$$1$$$, indicating that they are a trophic balance species within the ecosystem.
It is known that any independent trophic group in the ecosystem has a size of at most $$$k$$$. The task is to find the set of all trophic balance species in the ecosystem.
The first line contains exactly two integers $$$n$$$ and $$$m$$$, where $$$n$$$ (resp. $$$m$$$) denotes the number of nodes (resp. edges) in the directed graph $$$D$$$ induced by the investigated ecosystem. The nodes are numbered as $$$1, 2, \ldots, n$$$. Then, $$$m$$$ lines follow. The $$$i$$$-th line contains two integers $$$x_i$$$ and $$$y_i$$$ indicating a directed edge from node $$$x_i$$$ to node $$$y_i$$$.
Output on a single line the node identidiers of all trophic balance species in ascending order. For any two consecutive node identifiers, separate them by a space.
4 31 22 32 4
2
4 51 21 31 42 33 2
2 3 4
Name |
---|