Archive / 2021 / Selection Test
Building the artifact
Captain America has to go back in time and collect parts to build an artifact.
Some of these parts are interconnected with a powerful force. If there’s a connection from part A to part B. Captain must collect part B before collecting A.
Sometimes a part of an artifact can be connected with itself, making it impossible to collect it.
When he collects all the parts, he can build the artifact.
Input Format
- First line contains
n cthe number of parts and connections - Next
clines containa bindicating connections from partato partb
Output Format
Output “YES” if the artifact can be built, “NO” if it cannot be built.
Constraints
1 <= n <= 100,000
0 <= r <= 5000
Sample Input 0
2 1
1 0
Sample Output 0
YES
Open on HackerRank ↗ · Markdown source · Back to the archive