|
| 1 | +<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>    </td><td><p>Lun the dog has found an undirected graph in Shuseki Forest. The graph consisted of <i>N</i> vertices and some edges. The vertices of the graph were numbered 0 through <i>N</i>-1. Each edge connected a different pair of vertices.</p> |
| 2 | +<p></p> |
| 3 | +<p>You are given the description of the graph in a vector <string> <b>graph</b> with <i>N</i> elements, each containing <i>N</i> characters. For each <i>i</i> and <i>j</i>, <b>graph</b>[<i>i</i>][<i>j</i>] will be 'Y' if vertex <i>i</i> and vertex <i>j</i> are connected by an edge, and 'N' otherwise. (Note that for each <i>i</i>, <b>graph</b>[<i>i</i>][<i>i</i>] will be 'N': there are no self-loops.)</p> |
| 4 | +<p></p> |
| 5 | +<p>Lun is interested in <i>articulation pairs</i> in this graph. An <i>articulation pair</i> is an unordered pair of two different vertices whose deletion increases the number of connected components in the graph. (The deletion of a vertex also removes all edges incident with that vertex.)</p> |
| 6 | +<p></p> |
| 7 | +<p>Return the number of the articulation pairs in Lun's graph.</p></td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>    </td><td><table><tr><td>Class:</td><td>Fragile2</td></tr><tr><td>Method:</td><td>countPairs</td></tr><tr><td>Parameters:</td><td>vector <string></td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int countPairs(vector <string> graph)</td></tr><tr><td colspan="2">(be sure your method is public)</td></tr></table></td></tr><tr><td colspan="2"><h3>Limits</h3></td></tr><tr><td>    </td><td><table><tr><td>Time limit (s):</td><td>2.000</td></tr><tr><td>Memory limit (MB):</td><td>256</td></tr><tr><td>Stack limit (MB):</td><td>256</td></tr></table></td></tr><tr><td colspan="2"><h3>Notes</h3></td></tr><tr><td align="center" valign="top">-</td><td>You are not given the value of <i>N</i> explicitly, but you can determine it as the number of elements in <b>graph</b>.</td></tr><tr><td align="center" valign="top">-</td><td>Two vertices belong to the same connected component if and only if we can reach one of them from the other by following a sequence of zero or more edges.</td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>graph</b> will contain between 3 and 20 elements, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>Each element of <b>graph</b> will contain <i>N</i> characters, where <i>N</i> is the number of the elements in <b>graph</b>.</td></tr><tr><td align="center" valign="top">-</td><td>Each character of each element of <b>graph</b> will be either 'Y' or 'N'.</td></tr><tr><td align="center" valign="top">-</td><td>For each valid <i>i</i> and <i>j</i>, <b>graph</b>[<i>i</i>][<i>j</i>] will be equal to <b>graph</b>[<i>j</i>][<i>i</i>].</td></tr><tr><td align="center" valign="top">-</td><td>For each valid <i>i</i>, <b>graph</b>[<i>i</i>][<i>i</i>] will be 'N'.</td></tr><tr><td colspan="2"><h3>Examples</h3></td></tr><tr><td align="center" nowrap="true">0)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"NYNN", "YNYN", "NYNY", "NNYN"}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 3</pre></td></tr><tr><td><table><tr><td colspan="2"><p>The graph looks as follows:</p> |
| 8 | +<p></p> |
| 9 | +<img src="http://s6.postimg.org/dguz2x9mp/2b0.png"></img> |
| 10 | +<p></p> |
| 11 | +<p>The articulation pairs are (0, 2), (1, 2) and (1, 3).</p> |
| 12 | +<p>For example, here is why (0, 2) is an articulation pair: |
| 13 | +Currently there is one connected component. |
| 14 | +(It contains all four vertices.) |
| 15 | +If we remove the vertices 0 and 2, and all edges incident to these vertices, we will be left with two isolated vertices: 1 and 3. |
| 16 | +Each of these vertices now forms a different connected component, so the number of connected components increased from 1 to 2.</p></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">1)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"NYNNNN", "YNYNNN", "NYNNNN", "NNNNYN", "NNNYNY", "NNNNYN"}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 5</pre></td></tr><tr><td><table><tr><td colspan="2"><img src="http://s6.postimg.org/ew1lorh1d/2b1.png"></img> |
| 17 | +<p></p> |
| 18 | +<p>The articulation pairs are (0, 4), (1, 3), (1, 4), (1, 5) and (2, 4).</p></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">2)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"NNN", "NNN", "NNN"}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 0</pre></td></tr><tr><td><table><tr><td colspan="2"><img src="http://s6.postimg.org/6rthk0um9/2b2.png"></img> |
| 19 | +<p></p> |
| 20 | +<p>There are no articulation pairs.</p></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">3)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"NYNYNNYYNN", "YNNNYNYYNN", "NNNNYNNNYN", "YNNNYYNNNN", "NYYYNNNNYN", |
| 21 | + "NNNYNNNNYN", "YYNNNNNNNN", "YYNNNNNNYN", "NNYNYYNYNY", "NNNNNNNNYN"}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 9</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">4)</td><td></td></tr><tr><td>    </td><td><table><tr><td><table><tr><td><pre>{"NNNYNNYNNNNNNNYYNNNY", "NNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNN", "YNNNNNNNNNYNNNNNNNNN", "NNNNNNNYNNNNNYNNNNYN", |
| 22 | + "NNNNNNNNNNNNNNNNYNNY", "YNNNNNNNNNNNNYYYNYNN", "NNNNYNNNNNNNNYYNNNNN", "NYNNNNNNNYNNNNNNNNNN", "NNNNNNNNYNNNYNNNNNYN", |
| 23 | + "NNNYNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNYNNNNNNNYNN", "NNNNYNYYNNNNNNNNNNNN", "YNNNNNYYNNYNNNNNNNNN", |
| 24 | + "YNNNNNYNNNNNNNNNYNNN", "NNNNNYNNNNNNNNNYNYNN", "NNNNNNYNNNNNYNNNYNNN", "NNNNYNNNNYNNNNNNNNNN", "YNNNNYNNNNNNNNNNNNNN"}</pre></td></tr></table></td></tr><tr><td><pre>Returns: 42</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr></table><p>This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved. </p></body></html> |
0 commit comments