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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值