#1745. [Usaco2005 oct]Flying Right 飞行航班

[Usaco2005 oct]Flying Right 飞行航班

题目描述

Figuring that they cannot do worse than the humans have, Farmer John's cows have decided to start an airline. Being cows, they decide to cater to the heretofore-untapped market of cows as passengers. They plan to serve the cows who live along the western coast of Lake Michigan. Each morning, they will fly from the northern-most point of the coast southward towards Chicowgo, making many stops along the way. Each evening, they will fly back north to the northernmost point. They need your help to decide which passengers to carry each day. Each of n (1n104)n \ (1 \le n \le 10^4) farms numbered 1n1\dots n along the coast contains an airport (Farm 11 is northern-most;farm nn is southern-most). On this day,k (1k5×104)k \ (1 \le k \le 5\times 10^4) groups of cows wish to travel. Each group of cows wants to fly from a particular farm to another particular farm. The airline, if it wishes, is allowed to stop and pick up only part of a group. Cows that start a flight, however, must stay on the plane until they reach their destination. Given the capacity c (1c100)c \ (1 \le c \le 100) of the airplane and the groups of cows that want to travel, determine the maximum number of cows that the airline can fly to their destination.

为了表示不能输给人类,农场的奶牛们决定成立一家航空公司。她们计划每天早晨,从密歇根湖湖岸的最北端飞向最南端,晚上从最南端飞往最北端。在旅途中,航空公司可以安排飞机停在某些机场。他们需要你帮助来决定每天携带哪些旅客。沿着湖岸,有 nn 个由北至南编号为 11nn 的农场。每个农场都有一个机场。这天,有 kk 群牛想要乘坐飞机旅行。每一群牛想要从一个农场飞往另一个农场。航班可以在某些农场停下带上部分或全体的牛。奶牛们登机后会一直停留直至达到目的地提供给你飞机的容量 cc,同时提供给你想要旅行的奶牛的信息,请你计算出这一天的航班最多能够满足几只奶牛的愿望。

输入格式

  • Line 11: Three space-separated integers: k,nk,n, and cc.
  • Lines 2k+12\dots k+1: Each line contains three space-separated integers s,es,e, and mm that specify a group of cows that wishes to travel. The m (1mc)m \ (1 \le m \le c) cows are currently at farm ss and want to travel to farm e (se)e \ (s \neq e).
  • 第一行:33 个用空格隔开的整数 kknncc
  • 第二到 k+1k+1 行:每一行有 33 个用空格隔开的整数 sseemm。 表示有 mm 只奶牛想从农场 ss 乘飞机到农场 ee

输出格式

  • Line 11: The maximum number of cows that can be flown to their destination. This is the sum of the number of cows flown to their destination on the flight southward in the morning plus the number of cows flown to their destination on the flight northward in the evening.
  • 可以完成旅行的奶牛人数的最大值。
4 8 3
1 3 2
2 8 3
4 7 1
8 3 2
6

样例说明

INPUT DETAILS:
Four groups of cows, eight farms, and three seats on the plane.

33 群想要旅行的奶牛,88 个农场,飞机上有 33 个座位。早晨,飞机把 22 只牛从 11 带到 3311 只牛从 22 带到 8811 只牛从 44 带到 77。晚上,航班把 22 只牛从 88 带到 33

数据规模与约定

对于 100%100\% 的数据,1n1041 \le n \le 10^41k5×1041 \leq k \leq 5\times 10^41mc1001 \leq m \leq c \leq 100

题目来源

Gold