F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Golden Week

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 373    Accepted Submission(s): 124
Special Judge


Problem Description
The ACM kingdom has N cities, numbered from 1 to N. The capital is numbered 1. There are N ¨C 1 roads each connecting two cities in the kingdom such that there exactly one path between any pair of cities.

Now the Golden Week Vocation is coming. M travelers living in the capital are going to travel to other cities. Every traveler will start from the capital, and the ith traveler has chosen city Ci as his destination. As a manager of the travel agencies, Mr. Chopsticks decides to assign prices to the roads in the kingdom during the vocation. After some investigation, Mr. Chopsticks has found that every traveler has a budget for his trip, and if the total price of the roads in the path from the capital to his destination city is larger than his budget, he will give up his trip; otherwise he will pay for it to the travel agencies. Mr. Chopsticks wants to assign prices to roads so as to maximize the agenciesĄ¯ revenue. Could you help him? Each road should be assigned a price between 0 and 1000,000,000 inclusive.
 

Input
The input begins with an integer T (T<=50), indicating the number of test cases. Each case begins with two integers N and M (2 <= N <= 1000, 1 <= M <= 1000), indicating the number of cities and the number of travelers respectively. Then N ¨C 1 lines follow, where the ith line contains two integers $u_i$ and $v_i$ $(1 \leq u_i, v_i \leq N)$ indicating that the ith road connects the cities $u_i$ and $v_i$. The next M lines each contain two integers $C_i$ and $B_i$ $(1 \leq C_i \leq N, 1 \leq B_i \leq 1000 000 000)$, indicating the ith travelerĄ¯s destination and budget respectively.
 

Output
For each case, output a line containing the maximum revenue, followed by a line containing N ¨C 1 nonnegative integers, separated by one space, in which the ith integer denotes the price of the ith road. If there are multiple optimum solutions, output any of them.
 

Sample Input
2 2 3 1 2 2 3 2 5 2 9 4 4 1 2 1 3 2 4 2 4 2 7 4 5 3 6
 

Sample Output
10 5 19 4 6 1
 

Author
SYSU
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-11 20:23:07, Gzip enabled