#P13181. [GCJ 2017 Finals] Spanning Planning

    ID: 15049 远端评测题 60000ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2017矩阵树定理Special Judge随机化构造行列式Google Code Jam

[GCJ 2017 Finals] Spanning Planning

题目描述

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

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, TT. TT test cases follow. Each consists of one line with an integer KK: the desired number of spanning trees.

输出格式

For each test case, first output one line containing Case #x: y, where xx is the test case number (starting from 1), and yy is the number of nodes in your graph. (yy must be between 2 and 22, inclusive.) Then, output yy more lines. The ii-th of these lines represents the ii-th node in the graph, and must contain exactly yy characters. The jj-th character on the ii-th line should be 1 if the ii-th node and the jj-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 121-2, 131-3, 141-4, 242-4, and 343-4. The eight different spanning trees are defined by these sets of edges:

  • 121-2, 131-3, 141-4
  • 121-2, 131-3, 242-4
  • 121-2, 131-3, 343-4
  • 121-2, 141-4, 343-4
  • 121-2, 242-4, 343-4
  • 131-3, 141-4, 242-4
  • 131-3, 242-4, 343-4
  • 141-4, 242-4, 343-4

Limits

  • 1T3001 \leqslant T \leqslant 300.

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

  • 3K100003 \leqslant K \leqslant 10000.