ConnectedSubgraph
2016 TCO Regional Wildcard · 2016-03-24 · by cgy4ever
Problem Statement
Suppose that we are given a graph G and a set S that is a non-empty subset of the vertices of G. Let G(S) be a new graph. The vertices of G(S) are the vertices in the set S. Two vertices in G(S) are connected by an edge if and only if they are connected in the original graph G. Each such graph G(S) is called an induced subgraph of the graph G.
A graph with n vertices has 2^n - 1 distinct induced subgraphs. (Note that the set S must be non-empty. One of the 2^n - 1 induced subgraphs is the graph G itself.)
You are given an
- The vertices in G are numbered 0 through n-1, where n is their number.
- The value of n must be between 1 and 20, inclusive.
- Among the induced subgraphs of G there are exactly k connected graphs.
For each k that satisfies the given constraints there is at least one such graph G. If there are multiple solutions, you may choose any of them. Return the description of your chosen graph G: a
Constraints
- k will be between 1 and 65,535, inclusive.
6
Returns: {"NYN", "YNY", "NYN" }
Our output is a graph with 3 vertices and 2 edges: 0-1 and 1-2. This graph has 7 induced subgraphs. Among those, 6 are connected. These are the subgraphs induced by {0}, {1}, {2}, {0,1}, {1,2}, and {0,1,2}. Only the subgraph induced by {0,2} is not connected: it consists of two isolated vertices.
5
Returns: {"NNNNN", "NNNNN", "NNNNN", "NNNNN", "NNNNN" }
Our output is a graph with 5 vertices and no edges. Each induced subgraph with a single vertex is connected.
31
Returns: {"NYYYY", "YNYYY", "YYNYY", "YYYNY", "YYYYN" }
Note that the graph we choose may only have at most 20 vertices. We cannot output a graph with 31 nodes and no edges. Out output is a complete graph on 5 nodes. Each of its 31 induced subgraphs is obviously connected.
9
Returns: {"NYNNNN", "YNNNNN", "NNNYNN", "NNYNNN", "NNNNNY", "NNNNYN" }
1
Returns: {"N" }
Submissions are judged against all 111 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ConnectedSubgraph with a public method vector<string> construct(int k) · 111 test cases · 2 s / 256 MB per case