Codeforces Round #518 (Div. 2) C. Colored Rooks

描述

传送门:我是传送门

Ivan is a novice painter. He has $n$ dyes of different colors. He also knows exactly $m$ pairs of colors which harmonize with each other.

Ivan also enjoy playing chess. He has $5000$ rooks. He wants to take $k$ rooks, paint each of them in one of $n$ colors and then place this $k$ rooks on a chessboard of size $10^9×10^9$.

Let’s call the set of rooks on the board connected if from any rook we can get to any other rook in this set moving only through cells with rooks from this set. Assume that rooks can jump over other rooks, in other words a rook can go to any cell which shares vertical and to any cell which shares horizontal.

Ivan wants his arrangement of rooks to have following properties:

  • For any color there is a rook of this color on a board;
  • For any color the set of rooks of this color is connected;
  • For any two different colors $a b$ union of set of rooks of color $a$ and set of rooks of color $b$ is connected if and only if this two colors harmonize with each other.

Please help Ivan find such an arrangement.

输入

The first line of input contains 22 integers $n, m (1≤n≤100, 0≤m≤min(1000,n(n−1)/2)$ — number of colors and number of pairs of colors which harmonize with each other.

In next $m$ lines pairs of colors which harmonize with each other are listed. Colors are numbered from $1$ to $n$. It is guaranteed that no pair occurs twice in this list.

输出

Print $n$ blocks, $i-th$ of them describes rooks of $i-th$ color.

In the first line of block print one number $ai (1≤a_i≤5000)$ — number of rooks of color $i$. In each of next $ai$ lines print two integers $x$ and $y$ $(1≤x,y≤10^9)$ — coordinates of the next rook.

All rooks must be on different cells.

Total number of rooks must not exceed $5000$.

It is guaranteed that the solution exists.

样例

输入

3 2
1 2
2 3

输出

2
3 4
1 4
4
1 2
2 2
2 4
5 4
1
5 1

输入

3 3
1 2
2 3
3 1

输出

1
1 1
1
1 2
1
1 3

输入

3 1
1 3

输出

1
1 1
1
2 2
1
3 1

Note

Rooks arrangements for all three examples (red is color $1$, green is color $2$ and blue is color $3$).

img

img

img

If there are many correct answers you can print any. You should not maximize or minimize the number of rooks.

思路

  • 首先将点x放到(x,x)上(不需要真放,只需要最后输出即可

  • 点x全部放到x轴=x的这一条线上,每一组相连的都往上放一个

(具体看代码吧,在纸上画一下就明白了

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* ===============================================================
*
* Filename: C.cpp
*
* Link:
*
* Version: 1.0
* Created: 2018/10/25 01时20分24秒
* Revision: none
* Compiler: g++
*
* Author: 杜宁元 (https://duny31030.top/), duny31030@126.com
* Organization: QLU_浪在ACM
*
* ===============================================================
*/
#include <bits/stdc++.h>
using namespace std;
#define clr(a, x) memset(a, x, sizeof(a))
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define pre(i,a,n) for(int i=n;i>=a;i--)
#define ll long long
#define max3(a,b,c) fmax(a,fmax(b,c))
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1010;

vector<int> p[N];

int n,m,x,y;
int main()
{
ios
#ifdef ONLINE_JUDGE
#else
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
cin >> n >> m;
for(int i = 1;i <= m;i++)
{
cin >> x >> y;
p[x].push_back(i+n+1);
p[y].push_back(i+n+1);
}
for(int k = 1;k <= n;k++)
{
int tmp = p[k].size();
cout << tmp+1 << endl;
cout << k << " " << k << endl;
for(int i = 1;i <= tmp;i++)
{
cout << k << " " << p[k][i-1] << endl;
}
}
fclose(stdin);
// fclose(stdout);
return 0;
}