#P2341. [USACO03FALL / HAOI2006] 受欢迎的牛 G

    ID: 1301 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>图论20032006河南USACO各省省选强连通分量,缩点Tarjan

[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 AA likes BB, and BB likes CC, then AA also likes CC. There are NN 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: NN and MM. The next MM lines: each line contains two space-separated integers: AA and BB, meaning AA likes BB.

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 33 can be a star.

Constraints

  • For 10%10\% of the testdata, N20N \le 20, M50M \le 50.
  • For 30%30\% of the testdata, N103N \le 10^3, M2×104M \le 2 \times 10^4.
  • For 70%70\% of the testdata, N5×103N \le 5 \times 10^3, M5×104M \le 5 \times 10^4.
  • For 100%100\% of the testdata, 1N1041 \le N \le 10^4, 1M5×1041 \le M \le 5 \times 10^4.

Translated by ChatGPT 5