QOJ.ac

QOJ

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

#22465. מפגש הפרות הגדול

Statistics

Bessie מתכננת מפגש שנתי גדול לפרות מכל הארץ ורוצה המקום הנוח ביותר.

כל פרה גרה באחד מ-$N$ ($1 \le N \le 100,000$) אסמים ממוספרים $1..N$, מחוברים ב-$N-1$ דרכים וכולם נגישים מכולם. דרך $i$ מחברת $A_{i}$ ו-$B_{i}$ ($1 \le A_i \le N; 1 \le B_i \le N$), אורך $L_{i}$ ($1 \le L_{i} \le 1,000$). כל אחד מ-$N$ יכול לארח; באסם $i$ יש $C_{i}$ ($0 \le C_{i} \le 1,000$) פרות.

מרב נוחות הוא מזער אי-נוחות: ל-$X$, סכום מרחקי כל הפרות ל-$X$. אם מ-$i$ ל-$X$ מרחק 20, המרחק הכולל $C_{i}*20$. בחרו הטוב ביותר.

חמישה אסמים עם כמויות שונות בסוגריים מרובעים ודרכים באורכים שונים. ב-3 ו-4 אין פרות.

      1     3     4     5
      @--1--@--3--@--3--@[2]
     [1]    |
            2
            |
            @[1]
            2

אפשר בכל החמישה; טבלת אי-נוחות, B1–B5 אסמים והאחרון סכום.

מקום המפגש B1 B2 B3 B4 B5 סכום
1 0 3 0 0 14 17
2 3 0 0 0 16 19
3 1 2 0 0 12 15
4 4 5 0 0 6 15
5 7 8 0 0 0 15

אם המפגש ב-1, לכל אסם:

  • אסם 1: 0, אין נסיעה!
  • אסם 2: 3, מרחק $2+1=3$ כפול פרה אחת נותן 3.
  • אסם 3: 0, אין פרות!
  • אסם 4: 0, אין פרות!
  • אסם 5: 14, מרחק $3+3+1=7$ כפול שתי פרות נותן 14.

סך אי-נוחות 17.

הטוב ביותר 15, אפשר ב-3, 4, 5.

קלט

  • שורה 1: שלם $N$.
  • שורות $2..N+1$: שורה $i+1$ שלם $C_{i}$.
  • שורות $N+2..2N$: שורה $i+N+1$ שלושה שלמים $A_{i}$, $B_{i}$, $L_{i}$.

פלט

  • שורה 1: אי-נוחות מזערית אפשרית.

דוגמאות

קלט 1

5
1
1
0
0
2
1 3 1
2 3 2
3 4 3
4 5 3

פלט 1

15

מחבר: Jeffrey Wang, מתחרות, 2010

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.