luogu#P3544. [POI2012] BEZ-Minimalist Security
[POI2012] BEZ-Minimalist Security
题目描述
A map of Mafiatown's road network is given.
The network consists of intersections and bidirectional streets that connect them.
The streets cross only at the intersections, but they may lead through tunnels or flyovers.
Each pair of intersections is linked by at most one street.
At every intersection there is a police station manned by policemen.
A street linking the intersections and is considered safe if there are at least policemen in total in the two stations at the streets ends. Initially holds for every street.
However, due to an ongoing crisis the mayor Byteasar has ordained the Minimalist Security Act (MSA), which states that:
a certain number (which may be zero) of policemen is to be laid off from each police station (we denote the number of policemen laid off from the station at the intersection by ), after the layoff, the total number of the policemen at both ends of every street connecting some two intersections, say and , should equal exactly, i.e.:
These rules do not determine uniquely how many policemen are to be laid off.
Byteasar wonders what is the minimum and the maximum number of laid off policemen (the sum of values over all intersections) that complies with aforementioned rules.
一张n个点m条边的无向图,有点权有边权都是非负,且每条边的权值小于等于两个顶点的权值和,现在要将每个点减一个非负整数使得每条边权等于两个顶点的点权和,问最大修改代价和最小修改代价
输入格式
In the first line of the standard input there are two integers, and (, ), separated by a single space, that denote the number of intersections and the number of streets in Mafiatown, respectively.
The intersections are numbered from 1 to .
In the second line nonnegative integers separated by single spaces are given.
These are the numbers of policemen currently employed at successive stations, i.e., the values ().
Each of the following lines describes a single bidirectional street. Such description consists of three integers,(,,), separated by single spaces, that denote respectively: the numbers of the intersections at the ends of the street and the minimum total number of policemen that have to man the stations at those intersections.
输出格式
If Byteasar's ordinance can be carried out, your program should print, on the standard output, exactly one line with two integers separated by a single space.
The numbers should be the minimum and the maximum number of policemen that should be laid off in order to carry out the ordinance.
If carrying out the ordinance is impossible, your program should print a single line containing the word NIE (Polish for no).
3 2
5 10 5
1 2 5
2 3 3
12 15
提示
一张n个点m条边的无向图,有点权有边权都是非负,且每条边的权值小于等于两个顶点的权值和,现在要将每个点减一个非负整数使得每条边权等于两个顶点的点权和,问最大修改代价和最小修改代价