QOJ.ac

QOJ

Süre Sınırı: 2.0 s Bellek Sınırı: 256 MB Toplam puan: 100

#18901. 軟件套件

İstatistikler

Vasya 用現代套件管理器 Vum,喺 Vinux 作業系統入面安裝套件。

每個套件都有幾個可以安裝嘅版本。同一個應用程式一次只可以裝其中一個版本。我哋將某個應用程式嘅某個指定版本叫做一個套件。因為唔同應用程式嘅某啲版本可能互不兼容,Vum 入面有衝突呢個概念。每個衝突係一組套件,當中最多只可以裝一個套件。如果嘗試裝同一份衝突清單入面多過一個套件,系統就會崩潰,Vasya 唔想咁樣。

同一個應用程式嘅唔同版本可以有衝突,亦可以冇。一個衝突可以包括同一應用程式嘅幾個版本,甚至全部版本。

由於 Vum 嘅衝突描述系統相當原始,每個套件只可以列喺一個衝突入面。

Vasya 想裝 $N$ 個唔同嘅應用程式,又唔想整冧佢嘅 Vinux。佢要揀啱應用程式嘅版本,唔可以違反以上規則,但 Vum 嘅窮舉相依關係解析算法搞唔掂呢個任務。Vasya 想請你幫手處理佢嘅套件管理器。

輸入格式

輸入檔案第一行有一個整數 $N$,即係 Vasya 想裝嘅應用程式數目($1 \le N \le 200$)。

之後 $N$ 行提供應用程式嘅描述,包括佢哋嘅版本清單。一個應用程式描述由以下用空格分隔嘅欄位組成:

  • 應用程式名:由小寫拉丁字母組成、長度 1 至 10 個字元嘅字串;
  • 版本數目:唔大過 $1\,000$ 嘅正整數;
  • 版本號:按升序列出嘅正整數。

應用程式嘅編號唔大過 $100\,000$。所有應用程式名都唔同。

之後一行有個數 $K$,即係衝突嘅數目($0 \le K \le 500$)。

之後 $K$ 行描述衝突。每個衝突描述以正整數 $T$ 開頭,即係衝突入面嘅套件數目。跟住列出 $T$ 個用空格分隔嘅套件。每個套件先提供應用程式名,再提供版本號。

保證衝突清單入面嘅套件唔會重複,而且所有版本都喺應用程式描述入面提過。

輸出格式

如果冇辦法喺冇衝突之下裝晒 $N$ 個應用程式,輸出檔案唯一一行要有單字 No。如果得,第一行要有單字 Yes,第二行要列出為咗做到呢點而應該裝嘅版本號,用空格分隔。

呢 $N$ 個應用程式嘅版本要按佢哋喺輸入檔案描述嘅順序輸出。如果有幾種可行嘅揀法,輸出其中一種就得。

樣例

輸入格式 1

3
vim 3 1 2 3
nano 2 5 8
python 2 2 3
2
2 vim 3 nano 8
3 vim 1 nano 5 vim 2

輸出格式 1

Yes
2 8 2

輸入格式 2

2
firefox 1 38
chrome 1 46
1
2 firefox 38 chrome 46

輸出格式 2

No

說明

第一個樣例有兩個衝突。第一個衝突唔准同時裝 vim 第 3 個版本同 nano 第 8 個版本。第二個衝突話,vim 第 1 個版本、nano 第 5 個版本同 vim 第 2 個版本,只可以裝其中一個,或者一個都唔裝。正確方案如下:

  • 1 8 2
  • 1 8 3
  • 2 8 2
  • 2 8 3
  • 3 5 2
  • 3 5 3

第二個樣例有兩個應用程式,每個得一個版本。不過,唯一嘅衝突唔准將兩個應用程式一齊裝。

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.