1768.
Jedi Council
时间限制 1000 ms
内存限制 64 MB
> 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 $w_i$ of either $+W$ (for an aggressive master), or $-W$ (for an permissive master).
Jedi masters may have influences on each other. Given three masters $x_i$, $y_i$, and $z_i$ and parameters $a_i,b_i,c_i,d_i,e_i,f_i$, the level of influence is computed by
$$H_i = a_i|w_{x_i}-w_{y_i}| + b_i|w_{y_i}-w_{z_i}| + c_i|w_{z_i}-w_{x_i}| + d_i(w_{x_i}-w_{y_i}) + e_i(w_{y_i}-w_{z_i}) + f_i(w_{z_i}-w_{x_i}),$$
where $w_{x_i}$, $w_{y_i}$, and $w_{z_i}$ are the opinion scores of $x_i$, $y_i$, $z_i$, respectively.
Suppose that there are $p$ influences. The opinion of the Jedi Council is determined by:
$$\mathcal{O}=\sum_{i=1}^n w_i + \sum_{i=1}^p H_i$$
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 $w_x \le w_y$, $w_x = w_y$, or $w_x < w_y$.
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 $\mathcal{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.
输入数据
输出数据
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
\n
· · · \n
· · · · · · · · \n
· · \n