Magical Plants | 프로그래밍의 벗 PivotOJ
PivotOJ

Magical Plants

시간 제한: 3000ms메모리 제한: 1024MB출처: EIO 2020-21 openBOJ 29885

문제

John is growing plants on the windowsill. These are no ordinary plants: they are in telepathic communication with one another and will grow only if some other plants are already tall enough.

There are NN pots on the windowsill, numbered 1N1 \ldots N. Initially there is nothing planted in any of the pots. Also, there are MM constraints of the form "the plant in pot UiU_i can grow AiA_i metres tall only if the plant in ViV_i is already at least BiB_i metres tall".

Days consist of N+1N + 1 minutes. Each day, the following happens:

  1. On the ii-th minute (for every 1iN1 \le i \le N): if there is a plant growing in the ii-th pot, it will grow 1 metre taller unless that would violate one of the constraints.
  2. On the N+1N + 1-st minute: John can choose a pot with no plant in it, and plant a plant there. Initially, a plant is 1 metre tall.

We need each plant to be at least KK metres tall to brew a potion. Find the minimum number of days necessary, assuming John plants the plants optimally. Find one optimal way to plant the plants.

It is guaranteed that in all test cases it is possible to plant the plants so that all plants will grow KK metres tall in at most 101810^{18} days.

입력

The first line of the input consists of three space-separated integers NN, MM and KK (1N,M21051 \le N, M \le 2 \cdot 10^5, 2K1092 \le K \le 10^9).

The next MM lines describe the constraints. The ii-th such row consists of four integers UiU_i, AiA_i, ViV_i, BiB_i (1Ui,ViN1 \le U_i, V_i \le N, UiViU_i \ne V_i, 2Ai,BiK2 \le A_i, B_i \le K), describing a constraint.

출력

The first line of the output must consist of the minimum number of days needed for all plants to grow at least KK metres tall.

The second line must consist of NN integers, each from the interval 11091 \ldots 10^9. Of those, the ii-th should be the day John plants the ii-th plant.

If there are multiple optimal solutions, you can print any one of them.

예제

예제 1

입력
4 3 4
4 4 3 4
2 2 4 2
1 3 3 2
출력
7
2 4 3 1

예제 2

입력
5 4 1000000000
1 2 2 1000000000
2 2 3 1000000000
3 2 4 1000000000
4 2 5 1000000000
출력
4999999996
5 4 3 2 1
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.