Universal Cup Judging System

Universal Cup

Süre Sınırı: 1.5 s Bellek Sınırı: 512 MB Toplam puan: 100 Hack'lenebilir ✓
İstatistikler

Yana, Mino, White, and Huzz are best friends.

One day, the coach asked White, Mino, and Huzz to prepare a mock contest. Huzz designed a beautifully crafted search problem whose complexity is exponential with respect to $k$. He carefully checked the entire problem statement, except for one detail: he accidentally wrote $k \le 5 \times 10^5$ instead of $k \le 10$. Later, this problem appeared in a mock contest. The furious contestant, Yana, came to Huzz, asking how the problem was supposed to be solved. But he seemed to have forgotten something, and the problem statement he provided looked slightly different —

You are given a directed graph with $n$ vertices and $m$ edges, where each edge $e$ is assigned an integer weight $w(e)$ between $1$ and $8$.

A path is a sequence of edges $(e_1, e_2, \dots, e_\ell)$ such that the endpoint of $e_i$ is the startpoint of $e_{i+1}$ for all $1 \le i < \ell$. The length of the path is $\ell$, the number of edges it contains. Note that a path may contain the same edge multiple times.

The weight sequence of the path is the sequence of edge weights $[w(e_1), w(e_2), \dots, w(e_\ell)]$. Paths are compared by lexicographical order of their weight sequences.

Two paths are considered distinct as long as they use different edges, even if they share the same vertex sequence and weight sequence. For example, if both paths $(e_1, e_2)$ and $(e_3, e_4)$ have weight sequence [1,2], and both traverse vertices $1 \to 2 \to 3$, they are still distinct as long as $e_1 \neq e_3$ or $e_2 \neq e_4$.

White wants to find the lexicographically smallest $k$ paths. Since the total output may be too large, you only need to output the length of each path.

Input

The first line of the input contains three integers $n, m, k$ ($2 \le n \le 5 \times 10^5, 1 \le m \le 5 \times 10^5, 1 \le k \le 5 \times 10^5$), representing the number of vertices, the number of edges, and the required number of paths.

Each of the next $m$ lines contains three integers $x, y, z$ ($1 \le x, y \le n, 1 \le z \le 8, x \neq y$), representing a directed edge $e = (x, y)$ with weight $w(e) = z$. The given edge set may contain multiple edges.

Output

Print $k$ lines. The $i$-th line should contain a single integer, the length of the path whose weight is the $i$-th smallest in lexicographical order. If there are fewer than $i$ paths, output $-1$ instead.

Examples

input

5 5 8
2 1 1
3 1 2
4 1 1
1 5 2
5 2 1

output

1
1
1
2
3
4
5
6

input

3 4 10
1 2 1
1 2 1
2 3 2
2 3 3

output

1
1
2
2
2
2
1
1
-1
-1

input

6 5 15
1 2 3
2 3 5
3 4 2
3 5 1
5 6 4

output

1
2
1
1
2
3
4
3
1
1
2
3
2
-1
-1

Note

For simplicity, let $e_j$ denote the $j$-th input edge.

For the first testcase, the lexicographically smallest $8$ paths are:

  • Path $(e_1)$, weight sequence [1].
  • Path $(e_3)$, weight sequence [1].
  • Path $(e_5)$, weight sequence [1].
  • Path $(e_5, e_1)$, weight sequence [1,1].
  • Path $(e_5, e_1, e_4)$, weight sequence [1,1,2].
  • Path $(e_5, e_1, e_4, e_5)$, weight sequence [1,1,2,1].
  • Path $(e_5, e_1, e_4, e_5, e_1)$, weight sequence [1,1,2,1,1].
  • Path $(e_5, e_1, e_4, e_5, e_1, e_4)$, weight sequence [1,1,2,1,1,2].

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.