Vials 2
Time limit10sMemory limit1024 MB
Given a directed acyclic graph of vials and k chemicals in the first k vials, count intervals [l, r] above k by the maximum number of chemicals that can be moved into them.
- Level
Hard8 of 10
- Topics
- Graph, Two pointers, Bit manipulation
- Solved
- No attempts yet
Problem
Bajtazar is a chemist. Years ago he became known for an experiment that produced substance X. That substance did not solve all of humanity's problems, so this time he does not try to make it or any other particular solution. He simply experiments and evaluates the results.
Bajtazar's lab has vials numbered from 1 to , connected by tubes through which substances can flow. All vials are at pairwise different heights. Liquid in each tube can flow only downward. Each tube connects vial to vial , where vial is higher than vial . Each tube is pinched by a clamp that blocks the flow. At any moment Bajtazar can choose a clamp and open it, letting substance flow from to . Once all substance has flowed from one vial to the other, he closes the clamp again. Clamps are mechanical and holding one open takes effort, so at most one clamp can be open at any moment.
Vials to contain dangerous chemicals, each a different substance. Vials numbered greater than start empty.
The chemicals are extremely dangerous, and under no circumstances may different substances mix. Substances leave a microscopic residue, so a substance may not flow into a vial that previously held any other substance.
Bajtazar can only move substances between vials, making sure that no two of them mix. Moving them safely is useful, because he can carry each substance to a vial where it is more convenient to study.
The chemist wants to choose an interval with , move as many liquids as possible into vials in that interval, and study the chemicals placed there. He cannot decide which interval is best, so for every interval he wants to know the maximum number of different liquids that can be moved into vials numbered in . Write a program that, for each in , counts the intervals with .
Input
The first line contains three integers , , (; ; ; ), the number of vials, the number of tubes, and the number of vials that initially hold substances.
Each of the next lines contains two integers and (; ), meaning liquid can flow directly from vial to vial through a tube.
The lab description is valid. The directed graph with vials as vertices and tubes as edges has no cycles. Heights are not given, but for every pair of vials joined by a tube, it is known which vial is higher.
Output
Print lines. The -th line contains one integer: the number of intervals with and .
Hint
No tube leads into vial 7, so .
Bajtazar can move only one substance into each of the intervals , , , , , , , , and , so equals 1 for each of them. For the substance must come from vial 1, and it ends up in vial 3. For and it must be the substance from vial 2.
Suppose both substances are moved into . The substance poured into vial 4 has to pass through vial 5 and leave a residue there, which makes it impossible to bring the second substance into vial 5. For every other interval, Bajtazar can move both substances.