#P1344. [USACO4.4] 追查坏牛奶 Pollutant Control

[USACO4.4] 追查坏牛奶 Pollutant Control

Description

On your first day at Sanlu Milk Company, something unlucky happens: the company accidentally shipped a batch of milk containing melamine.

Unfortunately, by the time you discovered this, the melamine-tainted milk had already entered the delivery network. The network is large and complex. You know which retailer this batch is destined for, but there are many different routes to deliver it.

The delivery network consists of warehouses and transport trucks. Each truck carries milk in one direction between a fixed pair of warehouses. To trace and block the tainted milk, you must ensure it is not delivered to the retailer, so some transport trucks must be stopped. However, stopping each truck incurs a certain monetary loss.

Your task is to decide which trucks to stop so that the tainted milk cannot reach the retailer, while minimizing the total loss.

Input Format

The first line contains two integers NN and MM. NN is the number of warehouses, and MM is the number of transport trucks. Warehouse 11 is the factory (source), and warehouse NN is the retailer that the melamine-tainted milk is destined for.

Lines 2M+12\sim M+1 each contain three integers SiS_i, EiE_i, and CiC_i. Here, SiS_i and EiE_i are the starting and ending warehouse of this truck, respectively. CiC_i is the loss incurred by stopping this truck.

Output Format

Output two integers CC and TT. CC is the minimum total loss, and, among all solutions with minimum loss, TT is the minimum number of trucks that must be stopped.

4 5
1 3 100
3 2 50
2 4 60
1 2 40
2 3 80

60 1

Hint

Constraints: For 100%100 \% of the testdata, 2N322 \le N \le 32, 0M1030 \le M \le 10^3, 1SiN1 \le S_i \le N, 1EiN1 \le E_i \le N, 0Ci2×1060 \le C_i \le 2 \times 10^6.

Translation of the problem statement is from NOCOW.

USACO Training Section 4.4.

Translated by ChatGPT 5