#P2341. [USACO03FALL / HAOI2006] 受欢迎的牛 G
[USACO03FALL / HAOI2006] 受欢迎的牛 G
Description
Every cow dreams of becoming the star of the barn. A cow that is liked by all cows is a star cow. All cows are self-obsessed; each cow always likes itself. The “likes” relation is transitive—if likes , and likes , then also likes . There are cows in the barn. Given some admiration relationships between cows, please compute how many cows can be stars.
Input Format
The first line contains two space-separated integers: and . The next lines: each line contains two space-separated integers: and , meaning likes .
Output Format
Output a single integer on one line, the number of star cows.
3 3
1 2
2 1
2 3
1
Hint
Only cow number can be a star.
Constraints
- For of the testdata, , .
- For of the testdata, , .
- For of the testdata, , .
- For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号