CF402C.Searching for Graph

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

  • the graph contains exactly 2_n_ + 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 2_k_ + 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.

我们称一个包含 nn 个顶点的无向图为 pp-有趣图,当且仅当满足以下条件:

  • 该图恰好包含 2n+p2n + p 条边;
  • 该图不含自环和重边;
  • 对任意整数 kk(其中 1≤k≤n1 \leq k \leq n),由任意 kk 个顶点构成的任意子图至多包含 2k+p2k + p 条边。

图的一个子图是指图中某些顶点的集合以及某些边的集合;其中边的集合需满足:每条边的两个端点都必须属于所选的顶点集合。

你的任务是构造一个由 nn 个顶点组成的 pp-有趣图。

输入格式

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.

第一行包含一个整数 tt(1≤t≤51 \leq t \leq 5)—— 输入中测试用例的数量。接下来的 tt 行,每行包含两个以空格分隔的整数:nn、pp(5≤n≤245 \leq n \leq 24;p≥0p \geq 0;)—— 分别表示图中顶点的数量以及对应测试用例的兴趣值。

保证所要求的图一定存在。

输出格式

For each of the t tests print 2_n_ + p lines containing the description of the edges of a p-interesting graph: the i-th line must contain two space-separated integers a__i, b__i (1 ≤ a__i, b__i ≤ n; a__i ≠ b__i) — 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.

对于每个测试用例,输出 2n+p2n + p 行,每行描述一个 pp-interesting 图中的一条边:第 ii 行必须包含两个以空格分隔的整数 ai, bia_i,\ b_i(满足 1≤ai, bi≤n1 \leq a_i,\ b_i \leq n;且 ai≠bia_i \neq b_i),表示图中连接顶点 aia_i 与 bib_i 的一条边。图的顶点编号为 11 到 nn 的整数。

请按照输入中测试用例出现的顺序输出对应答案。若存在多种可行解,输出任意一种即可。

输入输出样例

  • 输入#1

    1
    6 0

    输出#1

    1 2
    1 3
    1 4
    1 5
    1 6
    2 3
    2 4
    2 5
    2 6
    3 4
    3 5
    3 6

输入解题思路,AI测评打分。不知道怎么写?

首页