Editorial for CCC '11 S4 - Blood Distribution


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: d

Create a graph representing which unit of blood can be accepted by a certain blood type. The top row represents units of blood, and the bottom row represents the patient's blood type.

There are 2 approaches to solve this problem.

Approach 1: Max Flow

Construct the appropriate max flow graph. Run any max flow algorithm and print the max flow.

One possible max flow algorithm is https://github.com/kth-competitive-programming/kactl/blob/main/content/graph/Dinic.h

Bonus: There is a max flow graph consisting of 10 vertices. 1 for the source, 1 for the sink, and 8 for the blood types. Try to find it.

Approach 2: Greedy

If a unit of blood exactly matches a patient's blood type, use this edge as much as possible. This removes 8 edges from the graph.

Next, A+, B+, and AB- blood can only be donated to AB+ patients. Also, O+, A-, and B- patients can only receive O- blood. Use these 6 edges as much as possible. This removes 6 edges from the graph. Now, the graph looks like this:

The O- blood and the AB+ patients can be done last. This leaves the following graph:

In summary:

  1. Max out these 8 edges: O- to O-, O+ to O+, A- to A-, ..., AB+ to AB+.
  2. Max out these 6 edges: A+/B+/AB- to AB+, O- to O+/A-/B-.
  3. Try a lot of possibilities for distributing O+/A-/B- blood to A+/B+/AB- patients. This handles 6 edges.
  4. Max out these 6 edges: O+/A-/B- to AB+, O- to A+/B+/AB-.
  5. Max out O- to AB+.

The official CCC test data is very weak, and the third step can be done in a lot of ways.

However, the DMOJ test data is much stronger, and it is much harder to implement the third step correctly. As a result, many people unironically suggest max flow as the easier solution.


Comments

There are no comments at the moment.