QOJ.ac

QOJ

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

#21265. ברית הפרות

Statistics

Bessie והפרות בחוות הסמוכות החליטו לחבר את החוות בשבילים כדי להתאחד נגד החקלאים. כל אחת מ־$N$ החוות ($1 \le N \le 100,000$) התבקשה לבנות שביל בדיוק לחווה אחת אחרת, בסך הכול $N$ שבילים. אחרי חודשים נבנו רק $M$ ($1 \le M < N$).

ויכוחים מי כבר בנתה שביל מאיימים לפלג את הברית. Bessie רוצה לספור איך נבנו $M$ השבילים הקיימים ולהרגיע את המתח. שביל בין 3 ו־4 יכול להיבנות בידי חווה 3 או 4. ספרו שיוכים של שבילים לחוות שבנו אותם מודולו 1,000,000,007. שני שיוכים שונים אם לפחות שביל אחד נבנה בידי חווה אחרת.

קלט

  • שורה 1: השלמים $N$ ו־$M$ המופרדים ברווח.
  • שורות $2..1+M$: שורה $i+1$ מתארת את שביל $i$ עם $u_{i}$ ו־$v_{i}$ המופרדים ברווח ($1 \le u_{i}, v_{i} \le N, u_{i} \ne v_{i}$), החוות המחוברות.

פלט

  • שורה 1: מספר השיוכים מודולו 1,000,000,007. אם שום שיוך אינו עומד בתנאים, הדפיסו 0.

דוגמאות

קלט 1

5 4
1 2
3 2
4 5
4 5

פלט 1

6

הסבר

ייתכנו שני שבילים בין אותו זוג חוות.

יש 6 שיוכים. $\{a,b,c,d\}$ פירושו שחווה 1 בונה שביל a, חווה 2 שביל b, חווה 3 שביל c וחווה 4 שביל d. השיוכים הם: $\{2, 3, 4, 5\}$ $\{2, 3, 5, 4\}$ $\{1, 3, 4, 5\}$ $\{1, 3, 5, 4\}$ $\{1, 2, 4, 5\}$ $\{1, 2, 5, 4\}$

מחבר הבעיה: Mark Gordon, 2011

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.