QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB

#23127. השמה תקפה

Statistics

נתון לכם גרף לא מכוון ללא לולאות עצמיות או קשתות מרובות.

הקצו ערך שלם אי-שלילי לכל קודקוד בגרף. השמה נקראת תקפה אם היא מקיימת שני תנאים:

  • לכל שני קודקודים שכנים יש ערכים הנבדלים זה מזה ב-$1$ בדיוק;
  • אם הערך של קודקוד קטן ממש מהערכים של כל שכניו, אז הוא שווה ל-$0$.

מצאו את מספר ההשמות התקפות מודולו $998\,244\,353$. שתי השמות נחשבות שונות אם קיים קודקוד שיש לו ערכים שונים בהשמות אלו.

קלט

השורה הראשונה מכילה מספר שלם $t$, מספר מקרי הבדיקה.

השורה הראשונה של כל מקרה בדיקה מכילה שני מספרים שלמים $n$ ו-$m$ ($2 \le n \le 10^6$, $1 \le m \le 10^6$): מספר הקודקודים והקשתות בגרף.

כל אחת מ-$m$ השורות הבאות מכילה שני מספרים שלמים $u$ ו-$v$ ($1 \le u, v \le n$, $u \ne v$): נקודות הקצה של הקשת המתאימה. הגרף אינו מכיל לולאות עצמיות או קשתות מרובות. לכל קודקוד יש לפחות שכן אחד.

סכום ערכי ה-$m$ על פני כל מקרי הבדיקה אינו עולה על $10^6$.

פלט

עבור כל מקרה בדיקה, הדפיסו מספר שלם אחד: מספר ההשמות התקפות מודולו $998\,244\,353$.

דוגמה

קלט 1

2
4 3
1 2
2 3
3 4
3 3
1 2
2 3
1 3

פלט 1

6
0

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.