#5303. [GCJ 2017 Finals] Spanning Planning

    ID: 5303 传统题 60000ms 1024MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>P131812017矩阵树定理Special Judge随机化构造行列式Google Code Jam

[GCJ 2017 Finals] Spanning Planning

[GCJ 2017 Finals] Spanning Planning

题目描述

A spanning tree of an undirected graph with $N$ nodes is a tree with $N-1$ edges that uses only edges from $N$ and includes all nodes in $N$.

Please construct a graph with at least 22 nodes, and no more than 2222 nodes, such that the graph has exactly KK different spanning trees. (Two spanning trees are considered different if and only if the sets of edges that they use are different.) The graph must have at most one edge per pair of nodes, and must not contain a loop (an edge from a node to itself).

It is guaranteed that at least one such graph exists for every KK within the limits below.

输入格式

The first line of the input gives the number of test cases, $T$. $T$ test cases follow. Each consists of one line with an integer $K$: the desired number of spanning trees.

输出格式

For each test case, first output one line containing `Case #x: y`, where $x$ is the test case number (starting from 1), and $y$ is the number of nodes in your graph. ($y$ must be between 2 and 22, inclusive.) Then, output $y$ more lines. The $i$-th of these lines represents the $i$-th node in the graph, and must contain exactly $y$ characters. The $j$-th character on the $i$-th line should be 1 if the $i$-th node and the $j$-th node are connected with an edge, and 0 otherwise. Note that this matrix will be symmetric and it will have all 0s along its main diagonal.

If multiple answers are possible, you may output any of them. Note that we guarantee that at least one valid answer exists for every KK within the limits below.

2
3
8
Case #1: 3
011
101
110
Case #2: 4
0111
1001
1001
1110

提示

**Sample Explanation**

In Case #1, the graph is a triangle, and removing any one edge creates a different spanning tree.

In Case #2, the available edges in our solution tree are 1−21-2, 1−31-3, 1−41-4, 2−42-4, and 3−43-4. The eight different spanning trees are defined by these sets of edges:

  • 1−21-2, 1−31-3, 1−41-4
  • 1−21-2, 1−31-3, 2−42-4
  • 1−21-2, 1−31-3, 3−43-4
  • 1−21-2, 1−41-4, 3−43-4
  • 1−21-2, 2−42-4, 3−43-4
  • 1−31-3, 1−41-4, 2−42-4
  • 1−31-3, 2−42-4, 3−43-4
  • 1−41-4, 2−42-4, 3−43-4

Limits

  • 1⩽T⩽3001 \leqslant T \leqslant 300.

Small dataset (30 Pts, Test Set 1 - Visible)

  • 3⩽K⩽100003 \leqslant K \leqslant 10000. 标签: P13181|2017|矩阵树定理|Special Judge|随机化|构造|行列式|Google Code Jam

来源

P13181|[GCJ 2017 Finals] Spanning Planning