QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#6109. 相似度圖

Statistics

令 $p$ 和 $q$ 為 $\{1, 2, \dots, N\}$ 的兩個排列。 $p$ 和 $q$ 的相似圖 $S(p, q)$ 定義如下:

  • $S(p, q)$ 具有 $N$ 個標記頂點,編號從 $1$ 到 $N$。
  • 頂點 $i$ 和 $j$ ($1 \le i < j \le N$) 之間存在一條邊,若且唯若 $p_i < p_j$ 且 $q_i < q_j$ 同時為真,或者同時為假。

給定一個具有 $N$ 個標記頂點(編號從 $1$ 到 $N$)的簡單無向圖 $G$。 請找出 $\{1, 2, \dots, N\}$ 的一對排列 $(p, q)$,使得 $S(p, q) = G$。

輸入格式

第一行包含一個整數 $N$。 接下來的 $N$ 行,每行包含 $N$ 個以空格分隔的整數。第 $i$ 行的第 $j$ 個整數 $E(i, j)$,若頂點 $i$ 和 $j$ 之間存在邊則為 $1$,否則為 $0$。

  • $1 \le N \le 100$
  • $0 \le E(i, j) \le 1$ ($1 \le i, j \le N$)
  • $E(i, j) = E(j, i)$ ($1 \le i < j \le N$)
  • $E(i, i) = 0$ ($1 \le i \le N$)

輸出格式

如果無法找到滿足條件的 $p$ 和 $q$,請輸出 NO。 否則,第一行輸出 YES。接下來兩行分別輸出 $p$ 和 $q$。如果有多組解,輸出其中任意一組即可。

範例

範例輸入 1

4
0 1 0 1
1 0 0 0
0 0 0 1
1 0 1 0

範例輸出 1

YES
1 2 3 4
2 4 1 3

範例輸入 2

6
0 1 0 1 0 1
1 0 0 0 1 0
0 0 0 1 1 1
1 0 1 0 0 0
0 1 1 0 0 0
1 0 1 0 0 0

範例輸出 2

NO

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.