AT_arc220_d.Long Trail
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a positive integer N.
Let G be a complete undirected graph with N vertices 1,2,…,N and 2N(N−1) edges.
Find a trail (v1,v2,…,vk) on G satisfying all of the following conditions.
- for all integers i such that 1≤i≤k−2, ∣vi−vi+2∣=1
- 2(N−2)2≤k
It can be proved that such a trail always exists under the constraints.
What is a trail? A sequence of vertices (v1,v2,…,vk) on an undirected graph G is called a trail on G if all of the following conditions are satisfied.
- 1≤vi≤N.
- For 1≤i≤k−1, there exists an edge connecting vertices vi and vi+1.
- For 1≤i<j≤k−1, the edge connecting vertices vi and vi+1 and the edge connecting vertices vj and vj+1 are distinct.
给定一个正整数 N。
令 G 是一个具有 N 个顶点 1,2,…,N 的无向完全图,共有 2N(N−1) 条边。
请在 G 上找出一条满足以下所有条件的迹(trail)(v1,v2,…,vk):
- 对所有满足 1≤i≤k−2 的整数 i,均有 ∣vi−vi+2∣=1;
- 2(N−2)2≤k。
在本题约束下,可以证明这样的迹总是存在的。
什么是迹(trail)?在无向图 G 上,一个顶点序列 (v1,v2,…,vk) 被称为 G 上的一条迹,当且仅当满足以下所有条件:
- 1≤vi≤N;
- 对所有 1≤i≤k−1,顶点 vi 与 vi+1 之间存在一条边;
- 对所有 1≤i<j≤k−1,连接顶点 vi 与 vi+1 的边和连接顶点 vj 与 vj+1 的边互不相同。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
Each test case is given in the following format:
N
输入从标准输入中以如下格式给出:
T
case1
case2
⋮
caseT
每个测试用例以如下格式给出:
N
输出格式
Output the answers for the test cases in order, separated by newlines.
For each test case, output a trail (v1,v2,…,vk) on G satisfying all conditions in the following format:
k
v1 v2 … vk
If multiple trails on G satisfying all conditions exist, any of them will be accepted.
按测试用例的顺序输出答案,各答案之间用换行符分隔。
对于每个测试用例,输出图 G 上一条满足所有条件的迹 (v1,v2,…,vk),格式如下:
k
v1 v2 … vk
若存在多条满足所有条件的图 G 上的迹,则输出任意一条均可。
输入输出样例
输入#1
2 3 5
输出#1
3 1 3 2 5 2 1 3 2 4 4 2 3 1 2
说明/提示
Sample 1 Explanation:
Consider the first test case.
For (v1,v2,v3)=(1,3,2),
- ∣v1−v3∣=∣1−2∣=1
- 2(N−2)2=21≤3
- The edge connecting vertices 1 and 3 and the edge connecting vertices 3 and 2 are distinct.
Thus, we can confirm that the sample output is a trail satisfying all conditions.
The following output, for example, is also accepted:
Constraints
- 1≤T≤50
- 3≤N≤1000
- The sum of N over all test cases is at most 1000.
- All input values are integers.
样例 1 解释:
考虑第一个测试用例。
对于 (v1,v2,v3)=(1,3,2),
- ∣v1−v3∣=∣1−2∣=1
- 2(N−2)2=21≤3
- 连接顶点 1 与 3 的边和连接顶点 3 与 2 的边是不同的边。
因此,我们可以确认该样例输出是一条满足所有条件的迹(trail)。
例如,以下输出同样可被接受:
约束条件
- 1≤T≤50
- 3≤N≤1000
- 所有测试用例的 N 之和不超过 1000。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?