QOJ.ac

QOJ

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

#21115. זמן מפגש

Statistics

Bessie ואחותה Elsie רוצות ללכת מהרפת לשדה האהוב, לצאת בדיוק יחד ולהגיע בדיוק יחד.

בחווה $N$ שדות ($1 \leq N \leq 100$) ממוספרים $1 \dots N$: ב־$1$ הרפת, $N$ האהוב. היא על מדרון: $X$ גבוה מ־$Y$ אם $X < Y$. $M$ שבילים מחברים זוגות, אך תלולים ולכן ניתן ללכת רק בירידה. בין $5$ ל־$8$ אפשר $5 \to 8$, אך לא להפך בעלייה. לכל זוג לכל היותר שביל אחד, לכן $M \leq N(N-1)/2$.

הזמנים עשויים להיות שונים: למשל Bessie צריכה $10$ יחידות ו־Elsie $20$. זמן נצרך רק בשבילים בין שדות: הן ממהרות, חוצות שדות בזמן כמעט אפס ולעולם אינן ממתינות בשום מקום.

מצאו את הזמן הקצר ביותר להגעה לשדה האהוב בדיוק באותו רגע.

קלט

השורה הראשונה מכילה $N$ ו־$M$ מופרדים ברווח.

$M$ השורות הבאות מתארות שביל בארבעה שלמים $A$ $B$ $C$ $D$: $A$ ו־$B$ ($A < B$) השדות המחוברים, $C$ זמן Bessie ו־$D$ זמן Elsie. $C$ ו־$D$ בטווח $1 \ldots 100$.

פלט

הדפיסו שלם יחיד, זמן ההגעה המשותפת המינימלי. אם אי אפשר, או Bessie או Elsie לא יכולה כלל להגיע לשדה האהוב, הדפיסו IMPOSSIBLE בשורה אחת.

דוגמאות

קלט 1

3 3
1 3 1 2
1 2 1 2
2 3 1 2

פלט 1

2

הערה

Bessie מהירה פי שניים בכל שביל, אך עם $1 \to 2 \to 3$ ל־Bessie ו־$1 \to 3$ ל־Elsie הן מגיעות יחד.

מחבר הבעיה: Nick Wu, 2015

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.