QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB

#23367. الفيروس

Statistics

ينتشر فيروس جديد يسمى الدودة عبر الشبكة. عندما يُصاب حاسوب بالدودة، تُصاب جميع الحواسيب المتصلة به عبر الشبكة أيضاً.

مثلاً، افترض أن سبعة حواسيب متصلة كما في الشكل 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.