CF733F.Drivers Dissatisfaction

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In one kingdom there are nn cities and mm two-way roads. Each road connects a pair of cities, and for each road we know the level of drivers dissatisfaction — the value wiw_{i} .

For each road we know the value cic_{i} — how many lamziks we should spend to reduce the level of dissatisfaction with this road by one. Thus, to reduce the dissatisfaction with the ii -th road by kk , we should spend kcik·c_{i} lamziks. And it is allowed for the dissatisfaction to become zero or even negative.

In accordance with the king's order, we need to choose n1n-1 roads and make them the main roads. An important condition must hold: it should be possible to travel from any city to any other by the main roads.

The road ministry has a budget of SS lamziks for the reform. The ministry is going to spend this budget for repair of some roads (to reduce the dissatisfaction with them), and then to choose the n1n-1 main roads.

Help to spend the budget in such a way and then to choose the main roads so that the total dissatisfaction with the main roads will be as small as possible. The dissatisfaction with some roads can become negative. It is not necessary to spend whole budget SS .

It is guaranteed that it is possible to travel from any city to any other using existing roads. Each road in the kingdom is a two-way road.

输入格式

The first line contains two integers nn and mm ( 2<=n<=21052<=n<=2·10^{5} , n1<=m<=2105n-1<=m<=2·10^{5} ) — the number of cities and the number of roads in the kingdom, respectively.

The second line contains mm integers w1,w2,...,wmw_{1},w_{2},...,w_{m} ( 1<=wi<=1091<=w_{i}<=10^{9} ), where wiw_{i} is the drivers dissatisfaction with the ii -th road.

The third line contains mm integers c1,c2,...,cmc_{1},c_{2},...,c_{m} ( 1<=ci<=1091<=c_{i}<=10^{9} ), where cic_{i} is the cost (in lamziks) of reducing the dissatisfaction with the ii -th road by one.

The next mm lines contain the description of the roads. The ii -th of this lines contain a pair of integers aia_{i} and bib_{i} ( 1<=ai,bi<=n1<=a_{i},b_{i}<=n , aibia_{i}≠b_{i} ) which mean that the ii -th road connects cities aia_{i} and bib_{i} . All roads are two-way oriented so it is possible to move by the ii -th road from aia_{i} to bib_{i} , and vice versa. It is allowed that a pair of cities is connected by more than one road.

The last line contains one integer SS ( 0<=S<=1090<=S<=10^{9} ) — the number of lamziks which we can spend for reforms.

输出格式

In the first line print KK — the minimum possible total dissatisfaction with main roads.

In each of the next n1n-1 lines print two integers x,vxx,v_{x} , which mean that the road xx is among main roads and the road xx , after the reform, has the level of dissatisfaction vxv_{x} .

Consider that roads are numbered from 11 to mm in the order as they are given in the input data. The edges can be printed in arbitrary order. If there are several answers, print any of them.

输入输出样例

  • 输入#1

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

    输出#1

    0
    1 1
    3 1
    6 1
    7 2
    8 -5
    
  • 输入#2

    3 3
    9 5 1
    7 7 2
    2 1
    3 1
    3 2
    2
    

    输出#2

    5
    3 0
    2 5
    
首页