QOJ.ac

QOJ

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

#21092. קישוט המרעים

Statistics

ל-Farmer John יש $N$ מרעים ($1 \leq N \leq 50,000$), שמספריהם $1...N$, המחוברים ב-$M$ דרכים דו-כיווניות ($1 \leq M \leq 100,000$). דרך $i$ מחברת $A_i$ ($1 \leq A_i \leq N$) ל-$B_i$ ($1 \leq B_i \leq N$), עם $A_i != B_i$. שתי דרכים עשויות לחבר אותו זוג.

Bessie מקשטת לכבוד יום הולדת FJ. רוצה בכל מרעה שלט גדול '$F$' או '$J$', אך כדי לא לבלבל אותו, מרעים המחוברים בדרך חייבים אותיות שונות.

החברה גובה על '$F$' יותר מעל '$J$', ולכן היא ממקסמת את מספר '$J$'. מצאו אותו או הדפיסו -1 אם אין סידור תקין.

קלט

  • שורה 1: השלמים $N$, $M$.
  • שורות $2..M+1$: השלמים $A_i$, $B_i$, המציינים דרך דו-כיוונית בין $A_i$ ל-$B_i$.

פלט

  • שורה 1: שלם המציין את מספר שלטי '$J$' המרבי. אם אין פתרון תקין, הדפיסו -1.

דוגמאות

קלט 1

4 4
1 2
2 3
3 4
4 1

פלט 1

2

הערה

המרעים והדרכים יוצרים קודקודים וצלעות של ריבוע.

Bessie יכולה לבחור מרעים 1 ו-3 ל-'$J$', או לחלופין 2 ו-4.

מחבר הבעיה: Kalki Seksaria, 2014

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.