CCO '00 P1 - Subsets

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 64M

Problem type
Canadian Computing Competition: 2000 Stage 2, Day 1, Problem 1

In this problem, you will write a program to find the minimal solution to a set of set inequalities. A set inequality has the format X contains S where X may be any set name and S may be a set name or set element. If S is a set name the inequality means that X is a superset or equal to S. If S is an element the inequality means that X contains S. Sets are named A-Z and contain elements from a-z.

The first line of input specifies the number of set inequalities (N). The next N lines each contain one set inequality. For each set name that appears in the input, your program must determine its minimal set: the smallest set of elements that the name must take in order that all of the inequalities hold. Output, in alphabetical order, each set name followed its minimal set, with the elements in alphabetical order, in the format shown below.

Sample Input

A contains B
A contains c
B contains d
F contains A
F contains z
X contains Y
Y contains X
X contains x
Q contains R

Sample Output

A = {c,d}
B = {d}
F = {c,d,z}
Q = {}
R = {}
X = {x}
Y = {x}


  • 1
    Plasmatic  commented on Aug. 8, 2018, 11:42 p.m. edit 2

    What is the maximum of N in this question?

    edit: The maximum of N ended up being irrelevant in my solution anyway :p

  • 3
    println_hi_  commented on May 4, 2017, 9:20 a.m.

    Is it guaranteed the sets won't be cyclic? i.e; if A contains B can B contain A

  • 0
    TypicalToxic  commented on Dec. 19, 2016, 11:08 p.m. edit 2

    Is there only 1 element per set? etc: A = {c, d, d}?.

    NVM. There's only 1 element per set.

  • 0
    raggarwal  commented on Feb. 8, 2015, 8:52 p.m. edited

    Will the set element always be char's?

    • 0
      YouZ  commented on Feb. 9, 2015, 11:38 p.m. edited

      Yeah it should be. That's what it said in the instructions.