Long TrailAI (CI翻译)
Problem Statement
You are given a positive integer $N$.
Let $G$ be a complete undirected graph with $N$ vertices $1,2,\ldots,N$ and $\displaystyle \frac{N(N-1)}2$ edges.
Find a trail $(v_1,v_2,\ldots,v_k)$ on $G$ satisfying all of the following conditions.
- for all integers
$i$such that$1 \leq i \leq k-2$,$|v_i - v_{i+2}| = 1$ $\displaystyle \frac{(N-2)^2}2 \le k$
It can be proved that such a trail always exists under the constraints.
What is a trail? A sequence of vertices $(v_1,v_2,\ldots,v_k)$ on an undirected graph $G$ is called a trail on $G$ if all of the following conditions are satisfied. $1\le v_i\le N.$ For $1\le i\le k-1$, there exists an edge connecting vertices $v_i$ and $v_{i+1}$. For $1\le i < j \le k-1$, the edge connecting vertices $v_i$ and $v_{i+1}$ and the edge connecting vertices $v_j$ and $v_{j+1}$ are distinct.
Constraints
$1\le T\le 50$$3\le N\le 1000$- The sum of
$N$over all test cases is at most$1000$. - All input values are integers.
Input
The input is given from Standard Input in the following format:
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
Each test case is given in the following format:
N
Output
Output the answers for the test cases in order, separated by newlines.
For each test case, output a trail $(v_1,v_2,\ldots,v_k)$ on $G$ satisfying all conditions in the following format:
k
v_1 v_2 \ldots v_k
If multiple trails on $G$ satisfying all conditions exist, any of them will be accepted.
{"titleZh":"漫长的路径","bodyZh":"## 题目描述\n\n给定一个正整数 $N$。\n\n令 $G$ 为一个有 $N$ 个顶点 $1,2,\ldots,N$ 以及 $\displaystyle \\frac{N(N-1)}2$ 条边的完全无向图。\n\n请找出 $G$ 上的一条路径 $(v_1,v_2,\ldots,v_k)$,满足以下所有条件。\n\n- 对于所有满足 $1 \\leq i \\leq k-2$ 的整数 $i$,都有 $|v_i - v_{i+2}| = 1$\n- $\\displaystyle \\frac{(N-2)^2}2 \\le k$\n\n可以证明,在题目的约束条件下,这样的路径总是存在。\n\n什么是路径?对于无向图 $G$,顶点序列 $(v_1,v_2,\\ldots,v_k)$ 被称为 $G$ 上的一条路径,当且仅当满足以下所有条件:$1\\le v_i\\le N$。对于 $1\\le i\\le k-1$,存在一条连接顶点 $v_i$ 和 $v_{i+1}$ 的边。对于 $1\\le i < j \\le k-1$,连接顶点 $v_i$ 和 $v_{i+1}$ 的边,与连接顶点 $v_j$ 和 $v_{j+1}$ 的边互不相同。\n\n## 约束条件\n\n- $1\\le T\\le 50$\n- $3\\le N\\le 1000$\n- 所有测试用例中的 $N$ 之和不超过 $1000$。\n- 所有输入值均为整数。\n\n## 输入格式\n\n输入从标准输入按以下格式给出:\n\n\n\n如果存在多条满足所有条件的 \nT\n\\text{case}_1\n\\text{case}_2\n\\vdots\n\\text{case}_T\n`\n\n每个测试用例按以下格式给出:\n\n`\nN\n`\n\n## 输出格式\n\n按顺序输出各测试用例的答案,每个测试用例占一行。\n\n对于每个测试用例,请按以下格式输出一条满足所有条件的 $G$ 上的路径 $(v_1,v_2,\\ldots,v_k)$:\n\n`\nk\nv_1 v_2 \\ldots v_k\n$G$ 上的路径,输出其中任意一条即可通过。"}AI (CI翻译)
样例
2
3
5
3
1 3 2
5
2 1 3 2 4
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。