Responsive image

问题 1878 --Jedi Council

1878: Jedi Council

时间限制: 2 Sec  内存限制: 128 MB
提交: 1  解决: 1
[提交][状态][讨论版][命题人:]

题目描述

> A Jedi Council was an organized body of Jedi, typically Masters, serving the Jedi Order as an administrative body that governed the Order's academies, temples, and organizations such as the Jedi Service Corps.
>
> All of the Coruscant Councils appointed their own members through unanimous vote, and each had a designated leader. Governing for several centuries, all four Councils were dissolved in 19 BBY following the Sith plot known as Operation: Knightfall and Order 66, both military operations carried out legally by the Grand Army of the Republic.
>
> — Wookieepedia
The masters of Jedi Council are controversial with approving the proposal of Chancellor Palpatine that the Republic should build a clone army to fight against the separatist attacks after the Naboo Crisis. There has been debates about the proposal, but only a few had a slight feeling of the presence of the coming darkness. Largely, the result of this debate is manipulated by the Dark Lord.
This problem is about how the result of the debate is being changed.
The masters in the Jedi Council are either *aggressive* or *permissive*, and each will vote for his/her opinions. Suppose that there are n masters in the Council and the i-th master has an opinion score wi of either +W (for an aggressive master), or −W (for an permissive master).
Jedi masters may have influences on each other. Given three masters xi, yi, and zi and parameters ai,bi,ci,di,ei,fi, the level of influence is computed by
Hi=ai|wxi−wyi|+bi|wyi−wzi|+ci|wzi−wxi|+di(wxi−wyi)+ei(wyi−wzi)+fi(wzi−wxi),

where wxi, wyi, and wzi are the opinion scores of xi, yi, zi, respectively.
Suppose that there are p influences. The opinion of the Jedi Council is determined by:
O=∑i=1nwi+∑i=1pHi

The Dark Lord can silently influence the opinions of Jedi masters. He chose a subset of the masters and silently changed their minds (from aggressive to permissive, or from permissive to aggressive).
Furthermore, there are balances and Force bonds between the masters which should not be broken, otherwise the evil plan will be revealed by the cautious master Yoda. In particular, there are constraints over the opinions in the form of wx≤wy, wx=wy, or wx<wy.
Nobody knows the true opinion of the Jedi masters. The only thing we knew is that the Dark Lord is a true master of combinatorial optimization that had changed the minds of the masters such that the opinion of the entire Jedi Council (i.e., the value of O) is minimized, at the same time no constraint is violated.
It is the time for you to reveal the evil process of the Dark Lord. Given the constraints, you should find a plan that minimizes the Jedi Council's opinion.
 

输入描述

The first line of the input contains an integer T.
For each test case, the first line contains four integers n the number of Jedi masters (1≤n≤500), W the absolute value of their opinion scores (0≤W≤10^6), pthe number of influences between Jedi masters (0≤p≤1000), q the number of constraints (0≤n≤1000).
Then p lines follows, each contains 9 integers xi,yi,zi,ai,bi,ci,di,ei,fi, as mentioned in the problem (1≤xi,yi,zi≤n, 0≤ai,bi,ci,di,ei,fi≤1000).
The following q lines describe the constraints, each line contains three integers, x,y,r. 
r=0 indicates a constraint in the form of wx≤wy.
r=1 indicates a constraint in the form of wx=wy.
r=2 indicates a constraint in the form of wx<wy.
The input guarantees at least one solution exists.
 

输出描述

Output one line for each test case, the minimized Jedi Council’s opinion.
 

样例输入

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

样例输出

3

来源

 

[提交][状态]
ACM算法攻关部