C. Searching for Graph(cf)
1 second
256 megabytes
standard input
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.
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: n, p (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.
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 ≤ n; ai ≠ 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.
1
6 0
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)的更多相关文章
- Codeforces Round #236 (Div. 2) C. Searching for Graph(水构造)
题目大意 我们说一个无向图是 p-interesting 当且仅当这个无向图满足如下条件: 1. 该图恰有 2 * n + p 条边 2. 该图没有自环和重边 3. 该图的任意一个包含 k 个节点的子 ...
- 构造图 Codeforces Round #236 (Div. 2) C. Searching for Graph
题目地址 /* 题意:要你构造一个有2n+p条边的图,使得,每一个含k个结点子图中,最多有2*k+p条边 水得可以啊,每个点向另外的点连通,只要不和自己连,不重边就可以,正好2*n+p就结束:) */ ...
- SPOJ #442 Searching the Graph
Just CS rookie practice on DFS\BFS. But details should be taken care of: 1. Ruby implementation got ...
- CF_402C Searching for Graph 乱搞题
题目链接:http://codeforces.com/problemset/problem/402/C /**算法分析: 乱搞题,不明白题目想考什么 */ #include<bits/stdc+ ...
- Codeforces Round #236 (Div. 2)
A. Nuts time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputoutput:st ...
- Reading task(Introduction to Algorithms. 2nd)
Introduction to Algorithms 2nd ed. Cambridge, MA: MIT Press, 2001. ISBN: 9780262032933. Introduction ...
- CF1082解题报告
CF1082A Vasya and Book 模拟一下即可 \(Code\ Below:\) #include <bits/stdc++.h> using namespace std; c ...
- cf 542E - Playing on Graph
cf 542E - Playing on Graph 题目大意 给定一个\(n\le 1000\)个点的图 求经过一系列收缩操作后能否得到一条链,以及能得到的最长链是多长 收缩操作: 选择两个不直接相 ...
- 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 ...
随机推荐
- 安装ubuntu系统空间分配问题
以下是我安装linux系统(ubuntu)时的系统空间配置,以50G为例: 挂载点 大小 格式 分区类型 / 15G Ext4 主分区 /home 30G Ext4 逻辑分区 /boot 1G Ext ...
- 移动端禁止滑动的js处理方式
下面是禁止移动端滑动事件的方式,慎用 document.querySelector('body').addEventListener('touchmove', function (ev) { ...
- stm32实现iap远程固件更新
前提 想来做iap升级了,应该不是什么新手. 下面的程序需要用到一些简单的功能 串口收发数据开关总中断虽然本文标题是实现远程固件更新,但是具体远程方案本文不做详细说明,重点在于介绍mcu接收到新的固件 ...
- 常州模拟赛d7t1 亲戚
分析:把题目换个方式理解,就是把各个点排成一列,并且指定了若干对的先后次序,问你有多少种序列满足要求. 显然是一道dp题,直接推出方程似乎有点点困难,那么先看看数据特点. 1.有一些点满足fi=0,那 ...
- 微信小程序初探(二):阅读官方demo源码
阅读demo有助于理解逻辑,而且demo源码中应该包含了框架开发人员想要表达的意思的精华,先从app.js着手来阅读. 附带贴下说明: https://mp.weixin.qq.com/debug/w ...
- android从sdcard中读取bitmap
String sdcard_path=Environment.getExternalStorageDirectory().getCanonicalPath(); String file_path=sd ...
- 稍微成型点的用WEBSOCKET实现的实时日志LOG输出
难的是还是就地用JS显示出来相关的发布进度. 还好,花了一下午实现了. 可以移植到项目中去罗... websocket.py: import tornado.ioloop import tornado ...
- OpenJudge百炼习题解答(C++)--题2704:竞赛评分
题: 总时间限制: 1000ms 内存限制: 65536kB 描写叙述 现举行一次小竞赛,參赛的3支队伍,编号为1,2,3.每支队列轮流回答问题,假设回答正确,加10分;回答错误,扣10分;放弃 ...
- JAVA学习第四十一课 — 泛型的基本应用(一)
泛型是JDK1.5以后出现的安全机制,简化机制,提高安全性 泛型的长处 1.将执行时出现的问题ClassCastException转移到了编译时期 2.避免了强制转换的麻烦 <>在当操作的 ...
- Python3基础(三) 运算符
Python中的运算符大部分与C语言的类似,但也有很多不同的地方.这里就大概地罗列一下Python 3中的运算符. 一.算术运算符 运算符 描述 示例 x + y 加 10 + 20 = 30 x - ...