Utilitarianism 2

아직 제출이 없습니다시간 제한7초메모리 제한1024 MB

문제

To fight the COVID-19 pandemic, vaccines must be transported efficiently to the people. There are nn vaccine manufacturers (numbered from 11 to nn), mm hospitals (numbered from 11 to mm), and kk agents (numbered from 11 to kk) in RUN-land. Agents deliver vaccines from manufacturers to hospitals. The ii-th agent has an assignment to deliver c_ic\_i vaccines from manufacturer a_ia\_i to hospital b_ib\_i. The assignments are designed such that for any two agents, they must be assigned to different manufacturers or different hospitals, or both.

RUN-land has a very important law: no manufacturer can use more than one agent, and no hospital can receive vaccines from more than one agent. It is possible that not all agents will be called on to complete their assignments.

The agents play an important role in this battle with the pandemic. Therefore, they should be rewarded reasonably based on their merits. The principle known as Vickery-Clarke-Groves pricing states the social value of each agent as follows. Given a set of participating agents SS, let f(S)f(S) be the maximum possible count of vaccines delivered to hospitals, subject to the law stated above. Let UU be the set of all agents. Then the social value of each agent ee is f(U)f(Ue)f(U) - f(U \setminus \\{e\\})

In short, given that the agents always act to maximize the number of vaccines that are delivered, the social value of the agent corresponds to the decrease in the number of vaccines delivered if that agent does not participate.

Please determine the social value for all agents.

입력

The first line contains three integers nn, mm, and k (1n,m2,000k\ (1 \le n, m \le 2\\,000, 1kmin(8,000,n×m)1 \le k \le \min(8\\,000, n \times m).

The next kk lines contains three integers a_ia\_i, b_ib\_i, and c_i (1a_inc\_i\ (1 \le a\_i \le n, 1b_im1 \le b\_i \le m, 1c_i1012)1 \le c\_i \le 10^{12})

If iji \neq j, (a_i,b_i)(a_j,b_j)(a\_i, b\_i) \neq (a\_j, b\_j).

출력

Output kk lines, where the ii-th line contains a single integer denoting the social value of agent ii.