CF566B.Replicating Processes

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A Large Software Company develops its own social network. Analysts have found that during the holidays, major sporting events and other significant events users begin to enter the network more frequently, resulting in great load increase on the infrastructure.

As part of this task, we assume that the social network is 4n4n processes running on the nn servers. All servers are absolutely identical machines, each of which has a volume of RAM of 11 GB = 10241024 MB (1)^{(1)} . Each process takes 100 MB of RAM on the server. At the same time, the needs of maintaining the viability of the server takes about 100100 more megabytes of RAM. Thus, each server may have up to 99 different processes of social network.

Now each of the nn servers is running exactly 44 processes. However, at the moment of peak load it is sometimes necessary to replicate the existing 4n4n processes by creating 8n8n new processes instead of the old ones. More formally, there is a set of replication rules, the ii -th ( 1<=i<=4n1<=i<=4n ) of which has the form of ai(bi,ci)a_{i}→(b_{i},c_{i}) , where aia_{i} , bib_{i} and cic_{i} ( 1<=ai,bi,ci<=n1<=a_{i},b_{i},c_{i}<=n ) are the numbers of servers. This means that instead of an old process running on server aia_{i} , there should appear two new copies of the process running on servers bib_{i} and cic_{i} . The two new replicated processes can be on the same server (i.e., bib_{i} may be equal to cic_{i} ) or even on the same server where the original process was (i.e. aia_{i} may be equal to bib_{i} or cic_{i} ). During the implementation of the rule ai(bi,ci)a_{i}→(b_{i},c_{i}) first the process from the server aia_{i} is destroyed, then appears a process on the server bib_{i} , then appears a process on the server cic_{i} .

There is a set of 4n4n rules, destroying all the original 4n4n processes from nn servers, and creating after their application 8n8n replicated processes, besides, on each of the nn servers will be exactly 88 processes. However, the rules can only be applied consecutively, and therefore the amount of RAM of the servers imposes limitations on the procedure for the application of the rules.

According to this set of rules determine the order in which you want to apply all the 4n4n rules so that at any given time the memory of each of the servers contained at most 99 processes (old and new together), or tell that it is impossible.

输入格式

The first line of the input contains integer nn ( 1<=n<=300001<=n<=30000 ) — the number of servers of the social network.

Next 4n4n lines contain the rules of replicating processes, the ii -th ( 1<=i<=4n1<=i<=4n ) of these lines as form ai,bi,cia_{i},b_{i},c_{i} ( 1<=ai,bi,ci<=n1<=a_{i},b_{i},c_{i}<=n ) and describes rule ai(bi,ci)a_{i}→(b_{i},c_{i}) .

It is guaranteed that each number of a server from 11 to nn occurs four times in the set of all aia_{i} , and eight times among a set that unites all bib_{i} and cic_{i} .

输出格式

If the required order of performing rules does not exist, print "NO" (without the quotes).

Otherwise, print in the first line "YES" (without the quotes), and in the second line — a sequence of 4n4n numbers from 11 to 4n4n , giving the numbers of the rules in the order they are applied. The sequence should be a permutation, that is, include each number from 11 to 4n4n exactly once.

If there are multiple possible variants, you are allowed to print any of them.

输入输出样例

  • 输入#1

    2
    1 2 2
    1 2 2
    1 2 2
    1 2 2
    2 1 1
    2 1 1
    2 1 1
    2 1 1
    

    输出#1

    YES
    1 2 5 6 3 7 4 8
    
  • 输入#2

    3
    1 2 3
    1 1 1
    1 1 1
    1 1 1
    2 1 3
    2 2 2
    2 2 2
    2 2 2
    3 1 2
    3 3 3
    3 3 3
    3 3 3
    

    输出#2

    YES
    2 3 4 6 7 8 10 11 12 1 5 9
    

说明/提示

(1)^{(1)} To be extremely accurate, we should note that the amount of server memory is 11 GiB = 10241024 MiB and processes require 100100 MiB RAM where a gibibyte (GiB) is the amount of RAM of 2302^{30} bytes and a mebibyte (MiB) is the amount of RAM of 2202^{20} bytes.

In the first sample test the network uses two servers, each of which initially has four launched processes. In accordance with the rules of replication, each of the processes must be destroyed and twice run on another server. One of the possible answers is given in the statement: after applying rules 11 and 22 the first server will have 22 old running processes, and the second server will have 88 ( 44 old and 44 new) processes. After we apply rules 55 and 66 , both servers will have 66 running processes ( 22 old and 44 new). After we apply rules 33 and 77 , both servers will have 77 running processes ( 11 old and 66 new), and after we apply rules 44 and 88 , each server will have 88 running processes. At no time the number of processes on a single server exceeds 99 .

In the second sample test the network uses three servers. On each server, three processes are replicated into two processes on the same server, and the fourth one is replicated in one process for each of the two remaining servers. As a result of applying rules 2,3,4,6,7,8,10,11,122,3,4,6,7,8,10,11,12 each server would have 77 processes ( 66 old and 11 new), as a result of applying rules 1,5,91,5,9 each server will have 88 processes. At no time the number of processes on a single server exceeds 99 .

首页