問題一覧 > 通常問題

No.3506 All Distance is Square Number

レベル : / AI推定難易度 : 1700 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 46
作問者 : toka0428 / テスター : Naru820 Nzt3 Solalyth
お気に入りにしたユーザー ProblemId : 13174 / 自分の提出
問題文最終更新日: 2026-04-18 09:50:06
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
CPCTF 2026: PPC (順位表) の他の問題:

Problem Statement

You are given a positive integer $N$. Construct one weighted connected undirected graph with $N$ vertices and $M$ edges that satisfies the following conditions. Here, the vertices are numbered from $1$ to $N$, and the edges are numbered from $1$ to $M$.

  • The graph contains no self-loops (multiple edges are allowed).
  • $M \leq 2N-3$
  • For every pair of integers $(i,j)$ satisfying $1 \leq i < j \leq N$, there exists a simple path from vertex $i$ to vertex $j$ such that the sum of the weights of the edges on the path is a perfect square.
  • The weights of all edges are pairwise distinct integers between $1$ and $200$, inclusive.

Furthermore, in the graph you construct, let $P_{i,j}$ be one simple path from vertex $i$ to vertex $j$ such that the sum of the weights of the edges on the path is a perfect square. Also, let $Q_{i,j}$ be the sequence of the numbers of the edges that $P_{i,j}$ passes through, arranged in the order they are traversed. Output $Q_{i,j}$ for every pair of integers $(i,j)$ satisfying $1 \leq i < j \leq N$.

It can be shown that a graph satisfying the conditions can always be constructed under the given constraints.

Constraints

  • $2 \leq N \leq 100$
  • All input values are integers.

Input

The input is given from Standard Input in the following format.

$N$

Output

First, output a graph satisfying the conditions. On the first line, output the number of edges $M$. On the $i$-th of the following $M$ lines, output the endpoints $U_{i}$, $V_{i}$ and the weight $C_{i}$ of edge $i$ in the following format.

$U_{i}$ $V_{i}$ $C_{i}$

Then, for every pair of integers $(i,j)$ satisfying $1 \leq i < j \leq N$, in lexicographical order of $(i,j)$, output in the following format.

$|Q_{i,j}|$  $Q_{i,j}$

Here, separate the elements of $Q_{i,j}$ with spaces.

Sample

Sample 1
Input
3
Output
3
1 2 16
2 3 9
1 3 25
1 1
1 3
1 2

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