QOJ.ac

QOJ

実行時間制限: 3.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#17268. 魔法樹林入面嘅伊凡王子

統計

伊凡王子(Ivan Tsarevich)為咗尋找不死科斯切伊(Koschei the Deathless)嘅死穴,嚟到咗一個魔法樹林。根據芭芭雅嘎(Baba Yaga)嘅講法,樹林入面有 $n$ 棵智慧橡樹,其中恰好有 $k$ 棵橡樹永遠講真話,而其餘嘅橡樹永遠講大話。

為咗知道接落嚟應該行去邊,王子需要向呢啲橡樹打聽後續嘅路線。不過,佢必須非常小心,因為如果佢聽信咗某棵講大話嘅橡樹嘅建議,佢就會誤入沼澤,俾獨眼怪利霍(Likho)伏擊。

為咗弄清楚邊啲橡樹可以信任,伊凡向每棵橡樹問咗一個問題,形式係:「第 $i$ 棵橡樹,請話我知,第 $a_i$ 棵橡樹係咪永遠講真話?」然而,佢唔知道點樣處理收到嘅回答。

請幫伊凡王子從呢啲問題入面得出結論。對於每棵橡樹,判斷佢係永遠講真話、永遠講大話,定係資訊唔足夠。如果芭芭雅嘎呃咗伊凡王子,根本唔存在任何滿足輸入數據嘅橡樹配置,請輸出單一個數字 $-2$。

輸入格式

第一行包含兩個整數 $n$ 同 $k$($1 \le n \le 5 \cdot 10^5$,$0 \le k \le n$),分別代表橡樹嘅數量同埋其中永遠講真話嘅橡樹數量。

接落嚟嘅第 $i$ 行(共 $n$ 行)包含兩個整數 $a_i$ 同 $b_i$($1 \le a_i \le n$,$0 \le b_i \le 1$),代表第 $i$ 棵橡樹被問到第 $a_i$ 棵橡樹係咪永遠講真話,如果 $b_i = 1$ 則回答為「係」,否則為「唔係」。

輸出格式

如果輸入數據互相矛盾,輸出單一個整數 $-2$。

否則,輸出 $n$ 個整數 $t_1, t_2, \dots, t_n$:關於每棵橡樹係咪講真話嘅結論。佢哋可以取以下數值:

  • $t_i = 1$,如果第 $i$ 棵橡樹永遠講真話;
  • $t_i = -1$,如果第 $i$ 棵橡樹永遠講大話;
  • $t_i = 0$,如果根據現有數據無法確定第 $i$ 棵橡樹係永遠講大話定係永遠講真話。

樣例

輸入格式 1

6 4
2 0
1 0
3 1
3 0
3 0
6 1

輸出格式 1

0 0 -1 1 1 1

輸入格式 2

3 1
2 0
3 0
1 0

輸出格式 2

-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.