QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100

#23908. 移動波

Statistics

題目描述

有 $N$ 個波,編號由 $1$ 到 $N$。另外,有 $N$ 個可以裝幾多個波都得嘅箱,箱嘅編號由 $1$ 到 $N$。

箱 $i$($1 \le i \le N$)一開始裝住波 $i$。

JOI 高中嘅學生葵由呢個狀態開始,對箱同波進行咗 $M$ 次操作。第 $j$ 次($1 \le j \le M$)操作係噉樣進行嘅:

  • 搵出裝住波 $X_j$ 嘅箱,由嗰個箱入面攞出波 $X_j$。然後,將波 $X_j$ 放入箱 $Y_j$。

喺葵做完晒全部 $M$ 次操作之後,請計算 $N$ 個波分別喺邊個箱入面。

數據範圍

  • $1 \le N \le 2000$。
  • $1 \le M \le 2000$。
  • $1 \le X_j \le N$($1 \le j \le M$)。
  • $1 \le Y_j \le N$($1 \le j \le M$)。
  • 輸入嘅所有數值都係整數。

輸入格式

輸入由標準輸入按以下格式給出:

N M
X_1 Y_1
X_2 Y_2
:
X_M Y_M

輸出格式

輸出 $N$ 行。第 $i$ 行($1 \le i \le N$)輸出喺葵做完晒全部 $M$ 次操作之後,波 $i$ 所在嘅箱嘅編號。

樣例

樣例輸入 1

3 4
1 2
3 2
2 1
1 3

樣例輸出 1

3
1
2

一開始,箱 $1$ 裝住波 $1$,箱 $2$ 裝住波 $2$,箱 $3$ 裝住波 $3$。

葵按以下方式進行咗 $4$ 次操作:

  • 喺第 $1$ 次操作入面,將波 $1$ 由箱 $1$ 攞出嚟之後,放入箱 $2$。
  • 喺第 $2$ 次操作入面,將波 $3$ 由箱 $3$ 攞出嚟之後,放入箱 $2$。
  • 喺第 $3$ 次操作入面,將波 $2$ 由箱 $2$ 攞出嚟之後,放入箱 $1$。
  • 喺第 $4$ 次操作入面,將波 $1$ 由箱 $2$ 攞出嚟之後,放入箱 $3$。

做完晒全部操作之後,波 $1$ 喺箱 $3$ 入面,波 $2$ 喺箱 $1$ 入面,波 $3$ 喺箱 $2$ 入面。因此,按呢個順序用換行隔開輸出 $3, 1, 2$。

樣例輸入 2

3 3
1 1
2 2
3 3

樣例輸出 2

1
2
3

做完晒全部操作之後,波 $1$ 喺箱 $1$ 入面,波 $2$ 喺箱 $2$ 入面,波 $3$ 喺箱 $3$ 入面。因此,按呢個順序用換行隔開輸出 $1, 2, 3$。

樣例輸入 3

4 2
1 3
2 4

樣例輸出 3

3
4
3
4

樣例輸入 4

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

樣例輸出 4

4
1
3
1

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.