CF180A.Defragmentation

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

The first line contains two integers nn and mm ( 1<=n,m<=2001<=n,m<=200 ) — the number of clusters and the number of files, correspondingly. Next mm lines contain descriptions of the files. The first number in the line is nin_{i} ( ni>=1n_{i}>=1 ), the number of clusters occupied by the ii -th file. Then follow nin_{i} numbers ai,1a_{i,1} , ai,2a_{i,2} , ..., ai,nia_{i,ni} ( 1<=ai,j<=n1<=a_{i,j}<=n ). It is guaranteed that each cluster number occurs not more than once and , that is, there exists at least one unused cluster. Numbers on each line are separated by spaces.

输入格式

In the first line print a single integer kk ( 0<=k<=2n0<=k<=2n ) — the number of operations needed to defragment the disk. Next kk lines should contain the operations' descriptions as " ii jj " (copy the contents of the cluster number ii to the cluster number jj ).

输出格式

Let's say that a disk consists of 88 clusters and contains two files. The first file occupies two clusters and the second file occupies three clusters. Let's look at examples of correct and incorrect positions of files after defragmentation.

Example 2: each file must occupy a contiguous area of memory.

Example 3: the order of files to each other is not important, at first the second file can be written, and then — the first one.

Example 4: violating the order of file fragments to each other is not allowed.

Example 5: unused clusters should be located at the end, and in this example the unused clusters are 33 , 77 , 88 .

输入输出样例

  • 输入#1

    7 2
    2 1 2
    3 3 4 5
    

    输出#1

    0
    
  • 输入#2

    7 2
    2 1 3
    3 2 4 5
    

    输出#2

    3
    2 6
    3 2
    6 3
    

说明/提示

Let's say that a disk consists of 88 clusters and contains two files. The first file occupies two clusters and the second file occupies three clusters. Let's look at examples of correct and incorrect positions of files after defragmentation.

Example 2: each file must occupy a contiguous area of memory.

Example 3: the order of files to each other is not important, at first the second file can be written, and then — the first one.

Example 4: violating the order of file fragments to each other is not allowed.

Example 5: unused clusters should be located at the end, and in this example the unused clusters are 33 , 77 , 88 .

首页