Under construction

Still being built. Things may change

Vials 2

Time limit10sMemory limit1024 MB

Summary
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 nn vials numbered from 1 to nn, connected by mm 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 aia_i to vial bib_i, where vial aia_i is higher than vial bib_i. 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 aia_i to bib_i. 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 11 to kk contain dangerous chemicals, each a different substance. Vials numbered greater than kk 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 [ℓ,r][\ell, r] with k+1≤ℓ≤r≤nk + 1 \le \ell \le r \le n, 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 [ℓ,r][\ell, r] he wants to know the maximum number of different liquids f(ℓ,r)f(\ell, r) that can be moved into vials numbered in [ℓ,r][\ell, r]. Write a program that, for each xx in [0,k][0, k], counts the intervals [ℓ,r][\ell, r] with f(ℓ,r)=xf(\ell, r) = x.

Input

The first line contains three integers nn, mm, kk (2≤n≤1052 \le n \le 10^5; 1≤m≤1061 \le m \le 10^6; 1≤k≤501 \le k \le 50; k<nk < n), the number of vials, the number of tubes, and the number of vials that initially hold substances.

Each of the next mm lines contains two integers aia_i and bib_i (1≤ai≤n1 \le a_i \le n; k+1≤bi≤nk + 1 \le b_i \le n), meaning liquid can flow directly from vial aia_i to vial bib_i 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 k+1k + 1 lines. The ii-th line contains one integer: the number of intervals [ℓ,r][\ell, r] with k+1≤ℓ≤r≤nk + 1 \le \ell \le r \le n and f(ℓ,r)=i−1f(\ell, r) = i - 1.

Hint

No tube leads into vial 7, so f(7,7)=0f(7, 7) = 0.

Bajtazar can move only one substance into each of the intervals [3,3][3, 3], [4,4][4, 4], [5,5][5, 5], [6,6][6, 6], [8,8][8, 8], [9,9][9, 9], [4,5][4, 5], [6,7][6, 7], and [7,8][7, 8], so ff equals 1 for each of them. For [3,3][3, 3] the substance must come from vial 1, and it ends up in vial 3. For [7,8][7, 8] and [8,8][8, 8] it must be the substance from vial 2.

Suppose both substances are moved into [4,5][4, 5]. 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.

Examples1

  1. Example 1

    Input
    9 10 2
    1 3
    1 5
    2 5
    5 4
    5 6
    2 6
    2 9
    2 8
    1 5
    1 9
    
    Expected output
    1
    9
    18