No.1571 All Your Cycles Are Same Lengths
タグ : / 解いたユーザー数 31
作問者 :
PCTprobability
/ テスター :
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もしくは右上の雲マークをクリックしてアカウントを作成してください。