C. Searching for Graph
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Let's call an undirected graph of n vertices p-interesting, if the following conditions fulfill:

  • the graph contains exactly 2n + p edges;
  • the graph doesn't contain self-loops and multiple edges;
  • for any integer k (1 ≤ k ≤ n), any subgraph consisting of k vertices contains at most 2k + p edges.

A subgraph of a graph is some set of the graph vertices and some set of the graph edges. At that, the set of edges must meet the condition: both ends of each edge from the set must belong to the chosen set of vertices.

Your task is to find a p-interesting graph consisting of n vertices.

Input

The first line contains a single integer t (1 ≤ t ≤ 5) — the number of tests in the input. Next t lines each contains two space-separated integers: np (5 ≤ n ≤ 24; p ≥ 0; ) — the number of vertices in the graph and the interest value for the appropriate test.

It is guaranteed that the required graph exists.

Output

For each of the t tests print 2n + p lines containing the description of the edges of a p-interesting graph: the i-th line must contain two space-separated integers ai, bi (1 ≤ ai, bi ≤ nai ≠ bi) — two vertices, connected by an edge in the resulting graph. Consider the graph vertices numbered with integers from 1 to n.

Print the answers to the tests in the order the tests occur in the input. If there are multiple solutions, you can print any of them.

Sample test(s)
input
1
6 0
output
1 2
1 3
1 4
1 5
1 6
2 3
2 4
2 5
2 6
3 4
3 5
3 6

这个题是A题的水平额。。是在考题意么。。

 #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
const int N=;
using namespace std; int main()
{
int t,n,p;
cin>>t;
while(t--)
{
cin>>n>>p;
int m = *n+p;
int cnt = ,flag = ;
for (int i = ;i <= n; i++)
{
for (int j = i+;j <= n; j++)
{
cout<<i<<" "<<j<<endl;
cnt++;
if (cnt==m)
{
flag = ;
break;
}
}
if (flag)
break;
}
}
return ;
}

C. Searching for Graph(cf)的更多相关文章

  1. Codeforces Round #236 (Div. 2) C. Searching for Graph(水构造)

    题目大意 我们说一个无向图是 p-interesting 当且仅当这个无向图满足如下条件: 1. 该图恰有 2 * n + p 条边 2. 该图没有自环和重边 3. 该图的任意一个包含 k 个节点的子 ...

  2. 构造图 Codeforces Round #236 (Div. 2) C. Searching for Graph

    题目地址 /* 题意:要你构造一个有2n+p条边的图,使得,每一个含k个结点子图中,最多有2*k+p条边 水得可以啊,每个点向另外的点连通,只要不和自己连,不重边就可以,正好2*n+p就结束:) */ ...

  3. SPOJ #442 Searching the Graph

    Just CS rookie practice on DFS\BFS. But details should be taken care of: 1. Ruby implementation got ...

  4. CF_402C Searching for Graph 乱搞题

    题目链接:http://codeforces.com/problemset/problem/402/C /**算法分析: 乱搞题,不明白题目想考什么 */ #include<bits/stdc+ ...

  5. Codeforces Round #236 (Div. 2)

    A. Nuts time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputoutput:st ...

  6. Reading task(Introduction to Algorithms. 2nd)

    Introduction to Algorithms 2nd ed. Cambridge, MA: MIT Press, 2001. ISBN: 9780262032933. Introduction ...

  7. CF1082解题报告

    CF1082A Vasya and Book 模拟一下即可 \(Code\ Below:\) #include <bits/stdc++.h> using namespace std; c ...

  8. cf 542E - Playing on Graph

    cf 542E - Playing on Graph 题目大意 给定一个\(n\le 1000\)个点的图 求经过一系列收缩操作后能否得到一条链,以及能得到的最长链是多长 收缩操作: 选择两个不直接相 ...

  9. CF 329C(Graph Reconstruction-随机化求解-random_shuffle(a+1,a+1+n))

    C. Graph Reconstruction time limit per test 3 seconds memory limit per test 256 megabytes input stan ...

随机推荐

  1. Java中对象流使用的一个注意事项

    再写jsp的实验作业的时候,需要用到java中对象流,但是碰到了之前没有遇到过的情况,改bug改到崩溃!!记录下来供大家分享 如果要用对象流去读取一个文件,一定要先判断这个文件的内容是否为空,如果为空 ...

  2. uva 272 Tex中的引号(Tex Quotes)

    TeX is a typesetting language developed by Donald Knuth. It takes source text together with a few ty ...

  3. mysql数据库主从操作记录

    master数据库已投入生产一段时间后,做主从复制的操作记录 环境: master库:172.18.237.13slave库:172.18.237.14 mysql版本说明: master:mysql ...

  4. 【Codeforces 484A】Bits

    [链接] 我是链接,点我呀:) [题意] 让你求出l~r当中二进制表示1的个数最多的数x [题解] 最多有64位 我们可以从l开始一直增大到r 怎么增大? 找到l的二进制表示当中0所在的位置 假设i这 ...

  5. hdu 1185 状压dp 好题 (当前状态与上两行有关系)

    /* 状压dp 刚开始&写成&&看了好长时间T0T. 状态转移方程 dp[i][k][j]=Max(dp[i][k][j],dp[i-1][l][k]+num[i][j]);( ...

  6. apt-get使用指南

    最近频繁使用apt-cache show(查看软件包详细信息)与apt-cache search(搜寻具体软件包确切名称)命令,深感方便与功能强大.现将一些apt-get相关命令做一个简单的收集: a ...

  7. $inject的用法

    controller后面的$inject是用来注入函数的变量名称的

  8. [bzoj1612][Usaco2008 Jan]Cow Contest奶牛的比赛_dfs

    Cow Contest奶牛的比赛 bzoj-1612 Usaco-2008 Jan 题目大意:题目链接. 注释:略. 想法: 我们对于每个点dfs,看一下比这个点大的点加上比这个点小的点是否是n-1即 ...

  9. Memcached的Web管理工具MemAdmin(待实践)

    Memcached的Web管理工具有很多,但是最好用的应该是MemAdmin.基于PHP5开发,所以部署时要注意环境. 介绍:http://www.junopen.com/memadmin/ 下载:h ...

  10. 源码分析-react2-根节点渲染

    //FiberNode{ alternate : '通过该属性和后面的切片进行比较', child : '改切片的子切片', firstEffect : '当前要加入的切片', stateNode : ...