Universal Cup Judging System

Universal Cup

Límite de tiempo: 1.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓
Estadísticas

仅使用电阻为 $1\,[\Omega]$ 的电阻器,构造一个电阻为 $\sqrt{D}\,[\Omega]$ 的电阻器。

给定一个正整数 $D$。请构造一个满足以下所有条件的连通无向图。在题目给定的约束下,可以证明这样的图总是存在的。

  • 顶点数 $N$ 在 $2$ 到 $300$ 之间(包含 $2$ 和 $300$),每个顶点都有从 $1$ 到 $N$ 的不同编号。
  • 边数 $M$ 最多为 $300$,允许存在自环和重边。
  • “从顶点 $1$ 到顶点 $N$ 的等效电阻”(定义如下)与 $\sqrt{D}$ 的绝对误差在 $\pm 10^{-6}$ 以内。

设 $G$ 是一个具有 $n$ 个顶点和 $m$ 条边的连通无向图($n \ge 2$),假设第 $j$ 条边连接顶点 $a_j, b_j$。考虑为图 $G$ 的每个顶点分配一个实数 $V_i$($i = 1, 2, \dots, n$),并为每条边分配一个实数 $I_j$($j = 1, 2, \dots, m$),使得以下所有方程成立:

  • $I_j = V_{a_j} - V_{b_j} \quad (j = 1, 2, \dots, m)$
  • $\sum_{b_j=i} I_j - \sum_{a_j=i} I_j = 0 \quad (i = 2, 3, \dots, n - 1)$
  • $\sum_{b_j=n} I_j - \sum_{a_j=n} I_j = 1$

可以证明这样的赋值总是存在的,并且 $V_1 - V_n$ 的值是唯一确定的。我们将此值定义为“从顶点 $1$ 到顶点 $n$ 的等效电阻”。

输入格式

输入为一个正整数 $D$。($1 \le D \le 5000$)

输出格式

第一行输出构造出的图的顶点数 $N$ 和边数 $M$,以空格分隔。

接下来的 $M$ 行中,第 $i$ 行($i = 1, 2, \dots, M$)应包含第 $i$ 条边的两个端点,以空格分隔。

如果存在多个满足条件的图,输出其中任意一个即可。

样例

输入格式 1

1

输出格式 1

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

说明

以下是样例 1 输出的示意图。

从顶点 $1$ 到顶点 $n$ 的等效电阻为 $1\,[\Omega]$,解释如下:

  • 由于所有电阻器的电阻均为 $1\,[\Omega]$,且根据对称性,顶点 $2$ 和 $3$ 的电势相等,因此它们之间的电阻器可以视为不存在。
  • 结果电路简化为两个并联的分支,每个分支由两个串联的 $1\,[\Omega]$ 电阻器组成。
  • 两个 $1\,[\Omega]$ 电阻器串联的等效电阻为 $2\,[\Omega]$,两个 $2\,[\Omega]$ 电阻器并联的等效电阻为 $1\,[\Omega]$。

以下输出也被视为正确:

2 1
1 2

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1532EditorialOpen题解jiangly2026-04-15 16:05:36View

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.