QOJ.ac

QOJ

时间限制: 1 s 内存限制: 128 MB

#23367. ウイルス

统计

ワームという新種のウイルスはネットワークを通じて広がります。あるコンピュータが感染すると、ネットワーク上でそれとつながっているすべてのコンピュータも感染します。

例えば、7 台のコンピュータが図 1 のようにつながっているとします。1 番のコンピュータが感染すると、ワームは 2 番と 5 番を経由して 3 番と 6 番にも広がり、2、3、5、6 番の計 4 台が感染します。しかし、4 番と 7 番はネットワーク上で 1 番とつながっていないので影響を受けません。

problem_23367_59082b7e2ece9da1b5eb568c85cadcd7.png

ある日、1 番のコンピュータがワームに感染しました。コンピュータの台数とネットワークの接続情報が与えられたとき、1 番を通じて感染するコンピュータの台数を出力するプログラムを作成してください。

入力

最初の行にコンピュータの台数が与えられます。台数は 100 以下で、コンピュータには 1 から順に番号が付けられています。

次の行に、ネットワーク上で直接つながっているコンピュータの組の数が与えられます。

続くその数の行には、直接つながっているコンピュータの番号の組が 1 行に一組ずつ与えられます。

出力

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.