#P10615. Infinite Self-Assembly
Infinite Self-Assembly
Infinite Self-Assembly
Automatic Chemical Manufacturing is experimenting with a process called self‐assembly. In this process, molecules (represented as squares) are allowed to attach to one another along their edges if the connector labels are compatible. Each edge’s connector label is either a two‐digit code "00" (which cannot connect to anything) or an uppercase letter followed by a sign (+ or −). Two connectors are compatible if they have the same letter but opposite signs; for example, A+ is compatible with A− (and vice‐versa) but not with A+ or B−.
You are given a collection of molecule types. Each molecule is described by 4 two‐character connector labels (one per edge). There is an unlimited supply of each type, and you may rotate or reflect a molecule arbitrarily when placing it. When a molecule is attached to an existing structure, one of its nonzero connector edges is used to bond to an already–available free edge and becomes hidden. The other three edges remain free. Only molecules that have at least two nonzero connectors can help propagate further growth because if a molecule has only one nonzero connector, then if that edge is used for connection, no free nonzero edge remains.
We say that the system can produce a structure of unbounded size if there is a way to attach molecules repeatedly so that one free edge (with some label) can be transformed into another free edge which eventually, after a series of attachments, cycles back to a label that can be repeated indefinitely. More formally, consider the following transformation. Suppose a free boundary edge has label X. To attach a new molecule, you must choose an edge on the molecule having label L that is complementary to X (i.e.
\(\text{comp}(X)=L\), where \(\text{comp}(A+)=A-\) and \(\text{comp}(A-)=A+\) for any letter \(A\)). When the molecule is attached using that edge, one of its other nonzero connector labels, call it M, becomes exposed. Thus the free edge changes from X to M (and the next molecule will have to match \(\text{comp}(M)\)).
For each molecule type that has at least two nonzero connectors (i.e. labels other than "00"), for every ordered pair of distinct nonzero labels \(L\) and \(M\) on that molecule, we may consider a transformation: if a free edge has label \(X\) and \(X=\text{comp}(L)\), then after attaching this molecule the new free edge becomes M. If there exists a cycle in such transformations then an arbitrarily long chain of attachments – and hence an unbounded structure – is possible.
Your task is to write a program to determine whether a given collection of molecule types can be assembled into a structure of unbounded size. Output unbounded
if an infinite assembly is possible, and bounded
otherwise.
Note: The connector "00" is not compatible with any edge.
inputFormat
The input consists of:
- A line containing a single integer \(n\) (the number of molecule types).
- \(n\) lines follow; each line contains 4 connector labels separated by spaces. Each connector label is exactly two characters (either "00" or an uppercase letter followed by + or -).
You may assume \(1 \le n \le 100\).
outputFormat
Output a single line containing either unbounded
if the molecules can assemble into a structure of unbounded size, or bounded
otherwise.
sample
2
A- A+ 00 00
A- 00 00 00
unbounded