QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22809. الاتصالات بالألياف

Statistics

يريد Farmer John ربط $N$ حظائر ($1 \le N \le 1{,}000$)، مرقمة $1..N$، بشبكة ألياف بصرية. تقع بدائرة حول بركة كبيرة، فلا يمكن ربط إلا المتجاورتين؛ الحظيرة $N$ تجاور 1.

لا يلزم ربط الجميع، فبعض أزواج الأبقار فقط تريد الاتصال. يريد أقل روابط تتيح الاتصال لجميع هذه الأزواج عبر الشبكة. أعط قائمة الأزواج، وأوجد أقل خطوط يلزم مدها. للاتصال من 1 إلى 3 يجب مد 1-2 و2-3.

الإدخال

  • السطر $1$: الصحيحان $N$ و$P$، الثاني عدد أزواج الاتصال ($1 \le P \le 10{,}000$).

  • الأسطر $2..P+1$: صحيحان يحددان زوج حظائر يرغب بالاتصال. لا زوج مكرر.

الإخراج

سطر واحد بصحيح، أقل عدد وصلات مباشرة مطلوبة.

أمثلة

الإدخال 1

5 2
1 3
4 5

الإخراج 1

3

ملاحظة

تصل أزواج الحظائر 1-2 و2-3 و4-5.

المصدر: Reid Barton، 2001.

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.