TopcoderArchiveVisit Topcoder
SRM19 Feb 2018
SRM 730

Subgraphs

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given an int k that is between 2 and 23, inclusive. Your task is to construct an undirected graph with some properties (listed below) and to locate some special subsets of nodes in the graph.



More precisely, your graph must satisfy the following:

  • The number n of nodes must be between 1 and 46, inclusive.
  • The nodes must be labeled from 0 to n-1.
  • The graph must be a simple undirected graph. (I.e., there cannot be any self-loops or multiple edges.)
  • For every number x between 0 and k*(k-1)/2, inclusive, there must be a way to choose exactly k nodes so that there will be exactly x edges between them.


Return a String[] with n + k*(k-1)/2 + 1 elements. The return value should look as follows:

  • The first n elements of the return value should contain the adjacency matrix of your graph. Character j of element i of the return value should be '1' of nodes i and j are connected by an edge and '0' if they aren't. Note that the main diagonal of the adjacency matrix must contain only '0's.
  • The remaining k*(k-1)/2 + 1 elements of the return value should describe the subsets of nodes that correspond to the last constraint the graph should satisfy. More precisely, the i-th of these Strings (0-based index) describes one set of k nodes such that the subgraph induced by these nodes contains exactly i edges. Encode the subset as a String of length n: character j of this string should be 'Y' if node j belongs into the subset and 'N' otherwise.


You may assume that there is always a graph with the desired properties. If there are multiple correct answers, you may return any of them.

Definition

Class:
Subgraphs
Method:
findGroups
Parameters:
int
Returns:
String[]
Method signature:
String[] findGroups(int k)
(be sure your method is public)

Constraints

  • k will be between 2 and 23, inclusive.

Examples

  1. 2
    Returns: {"010", "100", "000", "NYY", "YYN" }
    The returned graph has three nodes and only one edge: (0,1). The first set of nodes are the nodes {1,2}. There are no edges between these nodes. The second set of nodes are the nodes {0,1}. The corresponding subgraph contains one edge. Note that each node may appear in arbitrarily many of these sets.
  2. 3
    Returns: {"000000000000", "000000000000", "000000000000", "000010000000", "000100000000", "000000000000", "000000011000", "000000100000", "000000100000", "000000000011", "000000000101", "000000000110", "YYYNNNNNNNNN", "NNNYYYNNNNNN", "NNNNNNYYYNNN", "NNNNNNNNNYYY" }
    The graph described by the example return value has 12 nodes. It contains the following edges: (3,4), (6,7), (6,8), (9,10), (9,11), and (10,11). The sets of nodes described by the example return value are the following ones: The set {0,1,2} with 0 edges among these nodes. The set {3,4,5} with 1 edge among these nodes: the edge (3,4). The set {6,7,8} with 2 edges among these nodes: (6,7) and (6,8). The set {9,10,11} with 3 edges among these nodes: the remaining three edges.
  3. 4
    Returns: {"01111000", "10111100", "11011110", "11101111", "11110000", "01110000", "00110000", "00010000", "YNNNNYYY", "YYNNNNYY", "YNYNNNYY", "YNYNNYYN", "YNYNYYNN", "YNYYNYNN", "YYYYNNNN" }
Back to all problems