luogu#P1992. 不想兜圈的老爷爷
不想兜圈的老爷爷
Background
An elderly man in his seventies is walking through the countryside.
He does not want to walk in circles, because that would make him dizzy.
Happening to pass by, Xiao A, upholding the fine tradition of helping others, brings a map and wants to know whether the road conditions will certainly keep the old man clear‑headed.
usqwedf added: To make the fun contest truly fun, Xiao A would also like to ask you some math homework...
Problem Description
Task 1
Given a directed graph with vertices and edges, determine whether the graph has no cycles.
Task 2.1
Given an integer , compute .
Task 2.2
Given an integer , compute , and the answer does not need to be taken modulo anything.
Input Format
The first line contains three integers .
The next lines each contain two positive integers , indicating a directed edge .
Output Format
Task 1
If there are indeed no cycles (no cycles), output one line containing the string Yes.
If it is not the case that there are no cycles (there is a cycle), output one line containing the string No.
Task 2.1
If the answer to Task 1 is No, then ignore this task and output nothing.
If the answer to Task 1 is Yes, then (after outputting the answer to Task 1) output one line containing an integer for the answer.
Task 2.2
If the answer to Task 1 is Yes, then ignore this task and output nothing.
If the answer to Task 1 is No, then (after outputting the answer to Task 1) output one line containing an integer for the answer.
3 3 3
1 2
2 3
3 1
No
9
Hint
For 70% of the testdata, , , .
For 100% of the testdata, , , .
In particular, for at least 20% of the testdata, the answer to Task 1 is No.
Translated by ChatGPT 5