1. 程式人生 > >codeforces 1068C Colored Rooks (思維構造題)

codeforces 1068C Colored Rooks (思維構造題)

Colored Rooks

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 kkrooks, paint each of them in one of nn colors and then place this kkrooks 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 aaand 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

3 2
1 2
2 3

Output

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

Input

3 3
1 2
2 3
3 1

Output

1
1 1
1
1 2
1
1 3

Input

3 1
1 3

Output

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).

題意:給你 n 種顏色 、m 個顏色互相協調的關係。兩種顏色互相協調就是這兩種顏色的車,需要出現在同一行或者同一列至少一次。顏色不協調的車就不能在同一行、不能在同一列。 每種顏色的車至少出現一次,輸入這些車的座標。

思維不夠活躍,一直覺得構造題挺難的。想了好久也沒想的出來,最多過樣例。。難受(╯﹏╰)、

於是日常搜題解。。嘆氣.jpg

構造思路:首先保證每一種顏色的車都要出現,所以一開始 每一個(i,i) 都代表一種顏色的車。  然後從 n + 1 列開始構造,對於給出的m 對關係 xi,yi , 直接 在  (xi, n + i) , (yi,n + i) 放上車就行了。大概計算一下,這樣的構造方式 所用的車遠遠到不了5000

AC程式碼:

#include<bits/stdc++.h>
#define debug(x) cout << "[" << #x <<": " << (x) <<"]"<< endl
#define pii pair<int,int>
#define clr(a,b) memset((a),b,sizeof(a))
#define rep(i,a,b) for(int i = a;i < b;i ++)
#define pb push_back
#define MP make_pair
#define LL long long
#define INT(t) int t; scanf("%d",&t)
#define LLI(t) LL t; scanf("%I64d",&t)

using namespace std;

int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m)){
        vector<int> v[110];
        for(int i = 1;i <= n;i ++)
            v[i].pb(i);
        int x,y;
        int coun = n + 1;
        for(int i = 0;i < m;i ++){
            scanf("%d%d",&x,&y);
            v[x].pb(coun);
            v[y].pb(coun);
            coun ++;
        }
        for(int i = 1;i <= n;i ++){
            printf("%d\n",v[i].size());
            for(int j = 0;j < v[i].size();j ++)
                printf("%d %d\n",i,v[i][j]);
        }
    }
    return 0;
}