QOJ.ac

QOJ

Süre Sınırı: 1 s Bellek Sınırı: 128 MB

#23367. 病毒

İstatistikler

一种名为蠕虫的新型病毒会通过网络传播。一台计算机感染蠕虫病毒后,所有通过网络与它连通的计算机都会感染蠕虫病毒。

例如,假设七台计算机如图 1 所示连接。若 1 号计算机感染蠕虫病毒,病毒会经由 2 号和 5 号计算机传播到 3 号和 6 号计算机,使 2、3、5、6 这四台计算机感染。但 4 号和 7 号计算机在网络中与 1 号计算机不连通,因此不受影响。

problem_23367_59082b7e2ece9da1b5eb568c85cadcd7.png

某天,1 号计算机感染了蠕虫病毒。给定计算机的数量及它们在网络中的连接信息,请编写程序,输出通过 1 号计算机感染蠕虫病毒的计算机数量。

输入格式

第一行给出计算机数量。计算机数量不超过 100,计算机从 1 开始依次编号。

第二行给出网络中直接相连的计算机对数。

接下来给出相应数量的行,每行给出一对在网络中直接相连的计算机编号。

输出格式

在第一行输出:1 号计算机感染蠕虫病毒后,通过它感染蠕虫病毒的计算机数量。

样例

输入格式 1

7
6
1 2
2 3
1 5
5 2
5 6
4 7

输出格式 1

4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.