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 ...
随机推荐
- 巧用TWaver 3D 矢量图形功能
的确,提起TWaver,大家想到的首先是“电信拓扑图组件”.其实,由于其灵活的MVC架构.矢量化设计.方便定制等特点,TWaver可以做的还有很多.例如房地产行业常见到的“户型图”. 户型推荐是销售接 ...
- JUnit基本用法
JUnit的一些注意事项: 测试方法必须使用@Test修饰 测试方法必须使用public void进行修饰,不能带参数 一般使用单元测试会新建一个test目录存放测试代码,在生产部署的时候只需要将te ...
- Spring 使用注解注入 学习(四)
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- java8 lambda 函数式编程
package com.atguigu.java8; import java.util.ArrayList; import java.util.Comparator; import java.util ...
- 《Spring Boot 那些事》
<Spring Boot 那些事>----https://www.bysocket.com/?p=1124
- spring-boot | 整合通用Mabatis 分页插件PageHelper
Mybatis通用Mapper介绍 Mybatis 通用 Mapper 极其方便的使用 Mybatis 单表的增删改查,支持单表操作,不支持通用的多表联合查询 优点: 通用 Mapper 可以极大的方 ...
- Power of Matrix 等比数列求和 矩阵版!
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #inclu ...
- HDU——1576 A/B
A/B Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- [codevs 1243][网络提速(最短路分层思想)
题目:http://dev.codevs.cn/problem/1243/ 分析: 先容易想到将一个点拆成m个点,分别对应不同的边连过去,但是想不到控制加速器数量的办法.看了题解才知道,每个点的分层, ...
- js事件捕获和冒泡解析
<div id="box"> <div id="box2"> <p id="test">test< ...