#P8215. [THUPC 2022 初赛] 分组作业

[THUPC 2022 初赛] 分组作业

Problem Description

The teacher assigned a group project. Before that, the teacher had divided the 2n2n students in the class into nn groups, with two people in each group. Student 11 and student 22 are in one group, student 33 and student 44 are in one group, \ldots, and student 2n12n-1 and student 2n2n are in one group.

The teacher lets each team arrange the division of work by themselves. Whether they will cooperate becomes a big problem, so everyone decides to determine it by voting. First, each person decides whether they are willing to cooperate with their teammate. Different people have different willingness to cooperate due to their own reasons and the reasons related to their assigned teammate. For student ii, choosing “willing” produces dissatisfaction cic_i, and choosing “unwilling” produces dissatisfaction did_i.

If both teammates choose “willing”, then depending on the actual situation they may cooperate or may not cooperate. However, if one teammate chooses “unwilling”, then they can only not cooperate.

Among the students, there are also mm directed “like” relationships. Each relationship is of the form “AA likes BB”. In such a relationship, if AA does not cooperate with their teammate and BB chooses “willing”, then AA will feel a bit upset and produce dissatisfaction aia_i; if AA voted “unwilling” but BB successfully cooperates with their teammate, then AA will feel envy and produce dissatisfaction bib_i. (Since this setting would become strange when AA and BB are in the same group, the problem guarantees that this will not happen.) Here ii denotes the ii-th relationship.

If a student ii chooses “willing” but their teammate chooses “unwilling”, then they will have dissatisfaction eie_i because of their teammate.

Find the minimum possible total dissatisfaction over all cases.

Input Format

The first line contains two integers n,mn, m.

The next 2n2n lines each contain three integers ci,di,eic_i, d_i, e_i.

The next mm lines each contain four positive integers A,B,ai,biA, B, a_i, b_i.

Output Format

Output one integer in one line, representing the answer.

2 1
8 6 7
5 2 8
7 1 5
6 5 8
1 4 4 3
14

Hint

Constraints

It is guaranteed that 1n50001 \le n \le 5000, 0m100000 \le m \le 10000, and 1ai,bi,ci,di,ei1091 \le a_i, b_i, c_i, d_i, e_i \le 10^9.

Translated by ChatGPT 5