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. enote笔记语言(5)——其他(ver0.2)

    章节:其他   ((主:单词))                               用来醒目地强调这个句子中哪个词语作主语 sentence:                         ...

  2. Kattis - missinggnomesD Missing Gnomes (思路题)

    题目: 题意: 给出已经去除了几个数的一个序列,任务是将去除的数字插回去补全这个序列,输出字典序排在第一的那个补全的序列. 例如: 样例输入: 5 3 1 4 2 样例输出: 1 3 4 2 5 思路 ...

  3. axios在实际项目中的使用介绍

    1.axios本身就封装了各种数据请求的方法 执行 GET 请求 // 为给定 ID 的 user 创建请求 axios.get('/user?ID=12345') .then(function (r ...

  4. 洛谷 3870 [TJOI2009]开关

    [题解] 线段树基础题.对于每个修改操作把相应区间的sum改为区间长度-sum即可. #include<cstdio> #include<algorithm> #include ...

  5. wannafly-day1 Problem A - Birthday

    思路:队友贪心WA了,然后就没有然后了,自己也是第一次接触最小费用流的题.借这个题来学习一下,利用Spfa每次来找到一个最短的路径同时保存路径,每一次寻找最短路径就将这条路的最小费用流给剪掉,然后继续 ...

  6. log 框架 之间的关系

    日志框架分为两大部分 一部分是日志框架的抽象层,一部分是日志框架的具体实现 slf4j: 日志框架的抽象层 log4j,logback 日志框架的具体实现 如上图所示: slf4j的具体实现是:slf ...

  7. Codeforces Round #232 (Div. 2) On Sum of Fractions

    Let's assume that v(n) is the largest prime number, that does not exceed n; u(n) is the smallest pri ...

  8. scrapy——中间件UserAgent代理

    pip install fake-useragent 使用说明:from fake_useragent import UserAgent# 实例化一个UserAgent对象ua = UserAgent ...

  9. 用信号量及其PV操作处理实际问题

    43.现有3个生产者P1.P2.P3,他们都要生产橘子汁,每个生产者都已分别购得两种不同的原料,待购齐第三种原料后就可配制成橘子汁装瓶出售.有一供应商能源源不断的供应糖.水.橘子精,但每次只拿出一种原 ...

  10. 【CV论文阅读】Going deeper with convolutions(GoogLeNet)

    目的: 提升深度神经网络的性能. 一般方法带来的问题: 增加网络的深度与宽度. 带来两个问题: (1)参数增加,数据不足的情况容易导致过拟合 (2)计算资源要求高,而且在训练过程中会使得很多参数趋向于 ...