問題一覧 > 通常問題

No.1571 All Your Cycles Are Same Lengths

レベル : / AI推定難易度 : 1600 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 31
作問者 : PCTprobability / テスター : blackyuki
お気に入りにしたユーザー ProblemId : 6299 / 自分の提出
問題文最終更新日: 2022-02-06 21:50:39
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
灘校文化祭コンテスト 2021 day2 (順位表) の他の問題:

Problem Statement

Construct an undirected simple graph with $N$ vertices and $\displaystyle \frac{N(N-1)}{2}$ edges, that is, a complete graph on $N$ vertices, satisfying the following conditions.

  • The cost of each edge is an integer between $0$ and $100$, inclusive.
  • When starting from vertex $1$, passing through every vertex exactly $1$ time, and returning to vertex $1$, the sum of the costs of all edges traversed is always $T$.

You are given $Q$ test cases. Find the answer for each of them.

Input

$Q$
$N_1 \quad T_1$
$N_2 \quad T_2$
$\vdots$
$N_Q \quad T_Q$
  • The input consists of integers.
  • $1 \le Q \le 200$
  • $2 \le N \le 8$
  • $0 \le T \le 100$

Output

Let $S_i$ be the $i$-th answer. Output the results of the test cases separated by newlines, as follows.

$S_1$
$S_2$
$\vdots$
$S_Q$

For each test case, output as follows.

  • If a graph satisfying the conditions exists, output Yes. On the $i$-th of the following $\displaystyle \frac{N(N-1)}{2}$ lines, output $a_i \ b_i \ c_i$. This means that the $i$-th edge of the graph connects $a_i$ and $b_i$ and has cost $c_i$. The following conditions must be satisfied.
    • $1 \le a_i < b_i \le N$
    • If $i \neq j$, then $(a_i,b_i) \neq (a_j,b_j)$
    • $0 \le c_i \le 100$
    • When starting from vertex $1$, passing through every vertex exactly $1$ time, and returning to vertex $1$, the sum of the costs of all edges traversed is always $T$.

  • If no graph satisfying the conditions exists, output only No.

Sample

Sample 1
Input
1
4 4
Output
Yes
1 2 1
1 3 1
1 4 1
2 3 1
2 4 1
3 4 1

In the output graph, every edge has cost $1$, so when starting from vertex $1$, passing through every vertex exactly $1$ time, and returning to vertex $1$, the sum of the costs of all edges traversed is always $4$.

All the other conditions are also satisfied, so this graph meets the requirements.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。