QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 2048 MB Total points: 100

#265. Regular Bipartite Matching

Statistics

Given a $d$-regular bipartite graph $G=(X,Y,E)$, where $|X|=|Y|=n$ and every vertex has degree $d$, find a perfect matching.

Input

The first line contains two positive integers $n$ and $d$, as described in the problem statement.

The next $n$ lines each contain $d$ positive integers. If the $j$-th integer in the $(i+1)$-th line is $k$, it means there is an edge between $x_i$ and $y_k$. There may be multiple edges between the same pair of vertices.

It is guaranteed that the given graph is a $d$-regular graph.

Output

Output a single line containing $n$ integers, which is a permutation of $1, \dots, n$, representing a perfect matching. If $p_i = j$, it means the edge between $x_i$ and $y_j$ is part of the matching.

Examples

Input 1

4 2
3 4
1 3
2 2
1 4

Output 1

4 3 2 1

Subtasks

For $30\%$ of the data, it is guaranteed that $n \times d \le 2 \times 10^5$.

For another $30\%$ of the data, it is guaranteed that $d$ is a power of $2$.

For $100\%$ of the data, it is guaranteed that $n \times d \le 2 \times 10^6$.

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.