C. Colored Rooks
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Ivan is a novice painter. He has nn dyes of different colors. He also knows exactly mm pairs of colors which harmonize with each other.
Ivan also enjoy playing chess. He has 50005000 rooks. He wants to take kk rooks, paint each of them in one of nn colors and then place this kk rooks on a chessboard of size 109×109109×109.
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 aa bb union of set of rooks of color aa and set of rooks of color bb is connected if and only if this two colors harmonize with each other.
Please help Ivan find such an arrangement.
Input
The first line of input contains 22 integers nn, mm (1≤n≤1001≤n≤100, 0≤m≤min(1000,n(n−1)2)0≤m≤min(1000,n(n−1)2)) — number of colors and number of pairs of colors which harmonize with each other.
In next mm lines pairs of colors which harmonize with each other are listed. Colors are numbered from 11 to nn. It is guaranteed that no pair occurs twice in this list.
Output
Print nn blocks, ii-th of them describes rooks of ii-th color.
In the first line of block print one number aiai (1≤ai≤50001≤ai≤5000) — number of rooks of color ii. In each of next aiai lines print two integers xx and yy (1≤x,y≤1091≤x,y≤109) — coordinates of the next rook.
All rooks must be on different cells.
Total number of rooks must not exceed 50005000.
It is guaranteed that the solution exists.
Examples
input
Copy
3 2 1 2 2 3
output
Copy
2 3 4 1 4 4 1 2 2 2 2 4 5 4 1 5 1
input
Copy
3 3 1 2 2 3 3 1
output
Copy
1 1 1 1 1 2 1 1 3
input
Copy
3 1 1 3
output
Copy
1 1 1 1 2 2 1 3 1
Note
Rooks arrangements for all three examples (red is color 11, green is color 22 and blue is color 33).
第 i 色放在第 i 行 第 i 列 保证一色一行, 颜色间不影响
有关系的颜色 i 和 j , 在第 i 行和 j 行的右侧空余格子中同一列填上此行颜色
#include <bits/stdc++.h>
using namespace std;
const int mn = 5010;
int num[mn];
int mp[mn][5010];
int main()
{
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++)
mp[i][0] = i;
for (int i = 1; i <= m; i++)
{
int a, b;
scanf("%d %d", &a, &b);
mp[a][++num[a]] = 100 * a + b;
mp[b][++num[b]] = 100 * a + b;
}
for (int i = 1; i <= n; i++)
{
cout << num[i] + 1 << endl;
for (int j = 0; j <= num[i]; j++)
cout << i << ' ' << mp[i][j] << endl;
}
return 0;
}