QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 2048 MB Total points: 100

#10582. Buggy DFS

Statistics

你正在研究一种名为深度优先搜索(DFS)的图遍历算法。然而,由于一个 Bug,你的算法与标准 DFS 略有不同。以下是你的“Buggy DFS”(BDFS)算法,假设图有 $N$ 个节点(编号从 1 到 $N$):

BDFS():
    let S be an empty stack
    let FLAG be a boolean array of size N which are all false initially
    let counter be an integer initialized with 0

    push 1 to S

    while S is not empty:
        pop the top element of S into u
        FLAG[u] = true

        for each v neighbour of u in ascending order:
            counter = counter + 1
            if FLAG[v] is false:
                push v to S

    return counter

你意识到这个 Bug 使得该算法比标准 DFS 更慢,这可以通过函数 BDFS() 的返回值来研究。为了探究该算法的行为,你想要通过构造一个无向简单图来制作一些测试用例,使得函数 BDFS() 返回 $K$,或者确定是否无法做到这一点。

输入格式

一行,包含一个整数 $K$ ($1 \leq K \leq 10^9$)。

输出格式

如果无法构造一个使得函数 BDFS() 返回 $K$ 的无向简单图,则输出 -1 -1

否则,按以下格式输出该图。第一行包含两个整数 $N$ 和 $M$,分别表示图中的节点数和无向边数。接下来的 $M$ 行,每行包含两个整数 $u$ 和 $v$,表示连接节点 $u$ 和节点 $v$ 的一条无向边。你可以以任意顺序输出边。该图必须满足以下约束:

  • $1 \leq N \leq 32,768$
  • $1 \leq M \leq 65,536$
  • $1 \leq u, v \leq N$,对于所有边。
  • 该图是一个简单图,即没有重边或自环。

注意,你不必最小化节点数或边数。可以证明,如果存在一个使得 BDFS() 返回值为 $K$ 的图,则一定存在一个满足上述所有约束的图。如果存在多个解,你可以输出其中任意一个。

样例

样例输入 1

8

样例输出 1

3 3
1 2
1 3
2 3

样例输入 2

1

样例输出 2

-1 -1

样例输入 3

23

样例输出 3

5 7
4 5
2 3
3 1
2 4
4 3
2 1
1 5

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.