{"id":1213,"date":"2014-09-05T16:52:29","date_gmt":"2014-09-05T08:52:29","guid":{"rendered":"http:\/\/wx.wosign.com\/?p=1213"},"modified":"2014-09-05T16:52:29","modified_gmt":"2014-09-05T08:52:29","slug":"hnu-10104-%e7%97%85%e6%af%92-ac%e8%87%aa%e5%8a%a8%e6%9c%badfs","status":"publish","type":"post","link":"https:\/\/wx.wosign.com\/?p=1213","title":{"rendered":"Hnu 10104 \u75c5\u6bd2 (AC\u81ea\u52a8\u673a+dfs)"},"content":{"rendered":"<table style=\"font: 16px\/28px 'Helvetica Neue', Helvetica, Tahoma, Arial, STXihei, 'Microsoft YaHei', \u5fae\u8f6f\u96c5\u9ed1, sans-serif; color: #333333; text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; border-collapse: collapse; max-width: 100%; border-spacing: 0px; background-color: #ffffff; -webkit-text-stroke-width: 0px;\" bgcolor=\"#ffffff\">\n<tbody>\n<tr style=\"line-height: 1.8; font-size: 16px;\">\n<td style=\"line-height: 1.8; font-size: 16px;\" align=\"center\"><strong style=\"font-weight: bold;\">\u75c5\u6bd2<\/strong><\/td>\n<\/tr>\n<tr style=\"line-height: 1.8; font-size: 16px;\">\n<td style=\"line-height: 1.8; font-size: 16px;\" align=\"center\"><strong style=\"font-weight: bold;\">Time Limit:\u00a0<\/strong><span class=\"Apple-converted-space\">\u00a0<\/span>1000ms,\u00a0<span class=\"Apple-converted-space\">\u00a0<\/span><strong style=\"font-weight: bold;\">Special Time Limit:<\/strong><span class=\"Apple-converted-space\">\u00a0<\/span>2500ms,\u00a0<span class=\"Apple-converted-space\">\u00a0<\/span><strong style=\"font-weight: bold;\">Memory Limit:<\/strong><span class=\"Apple-converted-space\">\u00a0<\/span>32768KB<\/td>\n<\/tr>\n<tr style=\"line-height: 1.8; font-size: 16px;\">\n<td style=\"line-height: 1.8; font-size: 16px;\" align=\"center\"><strong style=\"font-weight: bold;\">Total submit users:<\/strong><span class=\"Apple-converted-space\">\u00a0<\/span>41,\u00a0<span class=\"Apple-converted-space\">\u00a0<\/span><strong style=\"font-weight: bold;\">Accepted users:\u00a0<\/strong><span class=\"Apple-converted-space\">\u00a0<\/span>23<\/td>\n<\/tr>\n<tr style=\"line-height: 1.8; font-size: 16px;\">\n<td style=\"line-height: 1.8; font-size: 16px;\" align=\"center\"><strong style=\"font-weight: bold;\">Problem 10104 :\u00a0<\/strong><span class=\"Apple-converted-space\">\u00a0<\/span>No special judgement<\/td>\n<\/tr>\n<tr style=\"line-height: 1.8; font-size: 16px;\">\n<td style=\"line-height: 1.8; font-size: 16px;\"><strong style=\"font-weight: bold;\">Problem description<\/strong><\/td>\n<\/tr>\n<tr style=\"line-height: 1.8; font-size: 16px;\">\n<td style=\"line-height: 1.8; font-size: 16px;\">\u4e8c\u8fdb\u5236\u75c5\u6bd2\u5ba1\u67e5\u59d4\u5458\u4f1a\u6700\u8fd1\u53d1\u73b0\u4e86\u5982\u4e0b\u7684\u89c4\u5f8b\uff1a\u67d0\u4e9b\u786e\u5b9a\u7684\u4e8c\u8fdb\u5236\u4e32\u662f\u75c5\u6bd2\u7684\u4ee3\u7801\u3002\u5982\u679c\u67d0\u6bb5\u4ee3\u7801\u4e2d\u4e0d\u5b58\u5728\u4efb\u4f55\u4e00\u6bb5\u75c5\u6bd2\u4ee3\u7801\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u79f0\u8fd9\u6bb5\u4ee3\u7801\u662f\u5b89\u5168\u7684\u3002\u73b0\u5728\u59d4\u5458\u4f1a\u5df2\u7ecf\u627e\u51fa\u4e86\u6240\u6709\u7684\u75c5\u6bd2\u4ee3\u7801\u6bb5\uff0c\u8bd5\u95ee\uff0c\u662f\u5426\u5b58\u5728\u4e00\u4e2a\u65e0\u9650\u957f\u7684\u5b89\u5168\u7684\u4e8c\u8fdb\u5236\u4ee3\u7801\u3002 \u4f8b\u5982\u5982\u679c{011, 11, 00000}\u4e3a\u75c5\u6bd2\u4ee3\u7801\u6bb5\uff0c\u90a3\u4e48\u4e00\u4e2a\u53ef\u80fd\u7684\u65e0\u9650\u957f\u5b89\u5168\u4ee3\u7801\u5c31\u662f010101\u2026\u3002\u5982\u679c{01, 11, 000000}\u4e3a\u75c5\u6bd2\u4ee3\u7801\u6bb5\uff0c\u90a3\u4e48\u5c31\u4e0d\u5b58\u5728\u4e00\u4e2a\u65e0\u9650\u957f\u7684\u5b89\u5168\u4ee3\u7801\u3002 \u4efb\u52a1\uff1a \u8bf7\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff1a \u8bfb\u5165\u75c5\u6bd2\u4ee3\u7801\uff1b \u5224\u65ad\u662f\u5426\u5b58\u5728\u4e00\u4e2a\u65e0\u9650\u957f\u7684\u5b89\u5168\u4ee3\u7801\uff1b \u5c06\u7ed3\u679c\u8f93\u51fa\u3002<\/td>\n<\/tr>\n<tr style=\"line-height: 1.8; font-size: 16px;\">\n<td style=\"line-height: 1.8; font-size: 16px;\"><strong style=\"font-weight: bold;\">Input<\/strong><\/td>\n<\/tr>\n<tr style=\"line-height: 1.8; font-size: 16px;\">\n<td style=\"line-height: 1.8; font-size: 16px;\">\u7b2c\u4e00\u884c\u5305\u62ec\u4e00\u4e2a\u6574\u6570n\uff0c\u8868\u793a\u75c5\u6bd2\u4ee3\u7801\u6bb5\u7684\u6570\u76ee\u3002\u4ee5\u4e0b\u7684n\u884c\u6bcf\u4e00\u884c\u90fd\u5305\u62ec\u4e00\u4e2a\u975e\u7a7a\u768401\u5b57\u7b26\u4e32\u2014\u2014\u5c31\u662f\u4e00\u4e2a\u75c5\u6bd2\u4ee3\u7801\u6bb5\u3002\u6240\u6709\u75c5\u6bd2\u4ee3\u7801\u6bb5\u7684\u603b\u957f\u5ea6\u4e0d\u8d85\u8fc730000\u3002<\/td>\n<\/tr>\n<tr style=\"line-height: 1.8; font-size: 16px;\">\n<td style=\"line-height: 1.8; font-size: 16px;\"><strong style=\"font-weight: bold;\">Output<\/strong><\/td>\n<\/tr>\n<tr style=\"line-height: 1.8; font-size: 16px;\">\n<td style=\"line-height: 1.8; font-size: 16px;\">\u8f93\u51fa\u4e00\u4e2a\u5355\u8bcd\uff1a TAK\u2014\u2014\u5047\u5982\u5b58\u5728\u8fd9\u6837\u7684\u4ee3\u7801\uff1b NIE\u2014\u2014\u5982\u679c\u4e0d\u5b58\u5728<\/td>\n<\/tr>\n<tr style=\"line-height: 1.8; font-size: 16px;\">\n<td style=\"line-height: 1.8; font-size: 16px;\"><strong style=\"font-weight: bold;\">Sample Input<\/strong><\/td>\n<\/tr>\n<tr style=\"line-height: 1.8; font-size: 16px;\">\n<td style=\"line-height: 1.8; font-size: 16px;\"><\/td>\n<\/tr>\n<tr style=\"line-height: 1.8; font-size: 16px;\">\n<td style=\"line-height: 1.8; font-size: 16px;\"><strong style=\"font-weight: bold;\">Sample Output<\/strong><\/td>\n<\/tr>\n<tr style=\"line-height: 1.8; font-size: 16px;\">\n<td style=\"line-height: 1.8; font-size: 16px;\">\n<pre class=\"prettyprint http\" style=\"margin: 0px 0px 1.5em; padding: 0.5em; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); color: #333333; line-height: 1.5em; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; font-size: 1em; display: block; white-space: pre-wrap; word-break: break-all; overflow-y: auto; word-wrap: break-word; background-color: #f8f8ff;\"><span class=\"attribute\" style=\"color: #008080;\">NIE<\/span><\/pre>\n<\/td>\n<\/tr>\n<tr style=\"line-height: 1.8; font-size: 16px;\">\n<td style=\"line-height: 1.8; font-size: 16px;\"><strong style=\"font-weight: bold;\">Problem Source<\/strong><\/td>\n<\/tr>\n<tr style=\"line-height: 1.8; font-size: 16px;\">\n<td style=\"line-height: 1.8; font-size: 16px;\" height=\"40\"><a style=\"color: #949494; font-style: italic; font-weight: bold; text-decoration: none; border-bottom-color: #949494; border-bottom-width: 1px; border-bottom-style: dashed; -webkit-transition: 0.25s; transition: 0.25s;\" href=\"http:\/\/acm.hnu.cn\/online\/?action=form&amp;type=submitproblem&amp;id=10104\" target=\"_blank\" rel=\"nofollow,noindex\">Submit<\/a><span class=\"Apple-converted-space\">\u00a0<\/span><a style=\"color: #949494; font-style: italic; font-weight: bold; text-decoration: none; border-bottom-color: #949494; border-bottom-width: 1px; border-bottom-style: dashed; -webkit-transition: 0.25s; transition: 0.25s;\" href=\"http:\/\/acm.hnu.cn\/online\/discuss\/?problemid=10104\" target=\"_blank\" rel=\"nofollow,noindex\">Discuss<\/a><span class=\"Apple-converted-space\">\u00a0<\/span><a style=\"color: #949494; font-style: italic; font-weight: bold; text-decoration: none; border-bottom-color: #949494; border-bottom-width: 1px; border-bottom-style: dashed; -webkit-transition: 0.25s; transition: 0.25s;\" href=\"http:\/\/acm.hnu.cn\/online\/?action=status&amp;problemid=10104&amp;courseid=0\" target=\"_blank\" rel=\"nofollow,noindex\">Judge Status<\/a><span class=\"Apple-converted-space\">\u00a0<\/span><a style=\"color: #949494; font-style: italic; font-weight: bold; text-decoration: none; border-bottom-color: #949494; border-bottom-width: 1px; border-bottom-style: dashed; -webkit-transition: 0.25s; transition: 0.25s;\" href=\"http:\/\/acm.hnu.cn\/online\/?action=problem&amp;type=list&amp;courseid=0\" target=\"_blank\" rel=\"nofollow,noindex\">Problems<\/a><span class=\"Apple-converted-space\">\u00a0<\/span><a style=\"color: #949494; font-style: italic; font-weight: bold; text-decoration: none; border-bottom-color: #949494; border-bottom-width: 1px; border-bottom-style: dashed; -webkit-transition: 0.25s; transition: 0.25s;\" href=\"http:\/\/acm.hnu.cn\/online\/?action=status&amp;rank=yes&amp;problemid=10104\" target=\"_blank\" rel=\"nofollow,noindex\">Ranklist<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"font: 16px\/28px 'Helvetica Neue', Helvetica, Tahoma, Arial, STXihei, 'Microsoft YaHei', \u5fae\u8f6f\u96c5\u9ed1, sans-serif; margin: 0px 0px 0.75em; color: #333333; text-transform: none; text-indent: 1em; letter-spacing: normal; word-spacing: 0px; white-space: normal; background-color: #ffffff; -webkit-text-stroke-width: 0px;\">\u9898\u76ee\u94fe\u63a5<\/p>\n<p style=\"font: 16px\/28px 'Helvetica Neue', Helvetica, Tahoma, Arial, STXihei, 'Microsoft YaHei', \u5fae\u8f6f\u96c5\u9ed1, sans-serif; margin: 0px 0px 0.75em; color: #333333; text-transform: none; text-indent: 1em; letter-spacing: normal; word-spacing: 0px; white-space: normal; background-color: #ffffff; -webkit-text-stroke-width: 0px;\">http:\/\/acm.hnu.cn\/online\/?action=problem&#038;type=show&#038;id=10104<\/p>\n<p style=\"font: 16px\/28px 'Helvetica Neue', Helvetica, Tahoma, Arial, STXihei, 'Microsoft YaHei', \u5fae\u8f6f\u96c5\u9ed1, sans-serif; margin: 0px 0px 0.75em; color: #333333; text-transform: none; text-indent: 1em; letter-spacing: normal; word-spacing: 0px; white-space: normal; background-color: #ffffff; -webkit-text-stroke-width: 0px;\">\u601d\u8def\u5206\u6790\uff1a<\/p>\n<p style=\"font: 16px\/28px 'Helvetica Neue', Helvetica, Tahoma, Arial, STXihei, 'Microsoft YaHei', \u5fae\u8f6f\u96c5\u9ed1, sans-serif; margin: 0px 0px 0.75em; color: #333333; text-transform: none; text-indent: 1em; letter-spacing: normal; word-spacing: 0px; white-space: normal; background-color: #ffffff; -webkit-text-stroke-width: 0px;\">\u4ed4\u7ec6\u5206\u6790\u5c31\u4f1a\u53d1\u73b0\uff0c\u5982\u679c\u5728ac\u81ea\u52a8\u673a\u4e0a\u5b58\u5728\u4e00\u4e2a\u73af\uff0c\u4e14\u8fd9\u4e2a\u73af\u4e0a\u6ca1\u6709\u5355\u8bcd\u7684\u672b\u5c3e\u8282\u70b9\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u3002<\/p>\n<p style=\"font: 16px\/28px 'Helvetica Neue', Helvetica, Tahoma, Arial, STXihei, 'Microsoft YaHei', \u5fae\u8f6f\u96c5\u9ed1, sans-serif; margin: 0px 0px 0.75em; color: #333333; text-transform: none; text-indent: 1em; letter-spacing: normal; word-spacing: 0px; white-space: normal; background-color: #ffffff; -webkit-text-stroke-width: 0px;\">\u4e3a\u4ec0\u4e48\u8fde\u5355\u8bcd\u7684\u672b\u5c3e\u8282\u70b9\u4e5f\u4e0d\u884c\u3002<\/p>\n<p style=\"font: 16px\/28px 'Helvetica Neue', Helvetica, Tahoma, Arial, STXihei, 'Microsoft YaHei', \u5fae\u8f6f\u96c5\u9ed1, sans-serif; margin: 0px 0px 0.75em; color: #333333; text-transform: none; text-indent: 1em; letter-spacing: normal; word-spacing: 0px; white-space: normal; background-color: #ffffff; -webkit-text-stroke-width: 0px;\">\u56e0\u4e3aac\u81ea\u52a8\u673a\u4e0a\u7684next\u6307\u5411\u4e86\u7684\u662f\u4e0e\u5b83\u5177\u6709\u6700\u957f\u540e\u7f00\u7b49\u4e8e\u524d\u7f00\u7684\uff0c\u5982\u679c\u8fd9\u4e2a\u65f6\u5019\u540e\u7f00\u6307\u5411\u4e86\u5355\u8bcd\u672b\u5c3e\u8282\u70b9\u7684\u524d\u9762\uff0c\u4e5f\u5c31\u610f\u5473\u7740\u6709\u4e00\u4e2a\u524d\u7f00\u5728\u8fd9\u4e2a\u672b\u5c3e\u8282\u70b9\u7684\u524d\u9762\uff0c\u90a3\u4e48\u8fd9\u4e2a\u73af\u603b\u4f1a\u51fa\u73b0\u4e00\u4e2a\u5355\u8bcd\u8282\u70b9\u3002<\/p>\n<p style=\"font: 16px\/28px 'Helvetica Neue', Helvetica, Tahoma, Arial, STXihei, 'Microsoft YaHei', \u5fae\u8f6f\u96c5\u9ed1, sans-serif; margin: 0px 0px 0.75em; color: #333333; text-transform: none; text-indent: 1em; letter-spacing: normal; word-spacing: 0px; white-space: normal; background-color: #ffffff; -webkit-text-stroke-width: 0px;\">\u6240\u4ee5\u5728dfs\u7684\u65f6\u5019\uff0c\u8981\u907f\u5f00\u4e00\u5207\u7684\u5355\u8bcd\u672b\u5c3e\u8282\u70b9\u3002<\/p>\n<p style=\"font: 16px\/28px 'Helvetica Neue', Helvetica, Tahoma, Arial, STXihei, 'Microsoft YaHei', \u5fae\u8f6f\u96c5\u9ed1, sans-serif; margin: 0px 0px 0.75em; color: #333333; text-transform: none; text-indent: 1em; letter-spacing: normal; word-spacing: 0px; white-space: normal; background-color: #ffffff; -webkit-text-stroke-width: 0px;\">\u81f3\u4e8edfs\u7684\u65f6\u5019\uff0c\u6211\u4eec\u8981\u5224\u65ad\u7684\u4e5f\u662f\u4e00\u6761\u8fde\u7eed\u7684\u94fe\u4e0a\u7684\u73af\uff0c\u6240\u4ee5\u5728\u6df1\u641c\u7684\u65f6\u5019\u75281\u53bb\u6807\u8bb0\uff0c\u7136\u540e\u56de\u6eaf\u7684\u65f6\u5019\uff0c\u6807\u8bb0\u6210\u53e6\u5916\u4e00\u4e2a\u3002<\/p>\n<p style=\"font: 16px\/28px 'Helvetica Neue', Helvetica, Tahoma, Arial, STXihei, 'Microsoft YaHei', \u5fae\u8f6f\u96c5\u9ed1, sans-serif; margin: 0px 0px 0.75em; color: #333333; text-transform: none; text-indent: 1em; letter-spacing: normal; word-spacing: 0px; white-space: normal; background-color: #ffffff; -webkit-text-stroke-width: 0px;\">\u7136\u540e\u6ca1\u6709\u6807\u8bb0\u7684\u4e3a0.<\/p>\n<p style=\"font: 16px\/28px 'Helvetica Neue', Helvetica, Tahoma, Arial, STXihei, 'Microsoft YaHei', \u5fae\u8f6f\u96c5\u9ed1, sans-serif; margin: 0px 0px 0.75em; color: #333333; text-transform: none; text-indent: 1em; letter-spacing: normal; word-spacing: 0px; white-space: normal; background-color: #ffffff; -webkit-text-stroke-width: 0px;\">\u8fd9\u6837\u5c31\u53ef\u4ee5\u627e\u5230\u94fe\u4e0a\u6210\u73af\u7684\u8282\u70b9\u4e86\u3002<\/p>\n<pre class=\"prettyprint cpp\" style=\"font: 16px\/1.5em Monaco, Menlo, Consolas, 'Courier New', monospace; margin: 0px 0px 1.5em; padding: 0.5em; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); color: #333333; text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; display: block; white-space: pre-wrap; word-break: break-all; overflow-y: auto; word-wrap: break-word; background-color: #f8f8ff; -webkit-text-stroke-width: 0px;\"><span class=\"preprocessor\" style=\"color: #999999; font-weight: bold;\">#include &lt;cstdio&gt;<\/span>\r\n<span class=\"preprocessor\" style=\"color: #999999; font-weight: bold;\">#include &lt;iostream&gt;<\/span>\r\n<span class=\"preprocessor\" style=\"color: #999999; font-weight: bold;\">#include &lt;cstring&gt;<\/span>\r\n<span class=\"preprocessor\" style=\"color: #999999; font-weight: bold;\">#include &lt;algorithm&gt;<\/span>\r\n<span class=\"preprocessor\" style=\"color: #999999; font-weight: bold;\">#include &lt;queue&gt;<\/span>\r\n<span class=\"preprocessor\" style=\"color: #999999; font-weight: bold;\">#define N 105<\/span>\r\n<span class=\"preprocessor\" style=\"color: #999999; font-weight: bold;\">#define maxn 30005<\/span>\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">using<\/span> <span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">namespace<\/span> <span class=\"built_in\" style=\"color: #0086b3;\">std<\/span>;\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">typedef<\/span> <span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">long<\/span> <span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">long<\/span> ll;\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">const<\/span> <span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> mod = <span class=\"number\" style=\"color: #009999;\">100000<\/span>;\r\n\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">const<\/span> <span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">char<\/span> tab = <span class=\"string\" style=\"color: #dd1144;\">'0'<\/span>;\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">const<\/span> <span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> max_next = <span class=\"number\" style=\"color: #009999;\">2<\/span>;\r\n\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> next[maxn][max_next],fail[maxn],num[maxn],siz;\r\n\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> newnode()\r\n{\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">for<\/span>(<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> i=<span class=\"number\" style=\"color: #009999;\">0<\/span>;i&lt;max_next;i++)\r\nnext[siz][i]=<span class=\"number\" style=\"color: #009999;\">0<\/span>;\r\nfail[siz]=num[siz]=<span class=\"number\" style=\"color: #009999;\">0<\/span>;\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">return<\/span> siz++;\r\n}\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">void<\/span> init()\r\n{\r\nsiz=<span class=\"number\" style=\"color: #009999;\">0<\/span>;\r\nnewnode();\r\n}\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">void<\/span> Insert(<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">char<\/span> *s,<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> len)\r\n{\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> p=<span class=\"number\" style=\"color: #009999;\">0<\/span>;\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">for<\/span>(<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> i=<span class=\"number\" style=\"color: #009999;\">0<\/span>;i&lt;len;i++)\r\n{\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> &amp;x=next[p][s[i]-tab];\r\np=x?x:x=newnode();\r\n}\r\nnum[p]++;\r\n}\r\n\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">void<\/span> acbuild()\r\n{\r\n<span class=\"stl_container\"><span class=\"built_in\" style=\"color: #0086b3;\">queue<\/span>&lt;<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span>&gt;<\/span>Q;\r\nQ.push(<span class=\"number\" style=\"color: #009999;\">0<\/span>);\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">while<\/span>(!Q.empty())\r\n{\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> temp=Q.front();\r\nQ.pop();\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">for<\/span>(<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> i=<span class=\"number\" style=\"color: #009999;\">0<\/span>;i&lt;max_next;i++)\r\n{\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> v=next[temp][i];\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">if<\/span>(v==<span class=\"number\" style=\"color: #009999;\">0<\/span>)next[temp][i]=next[fail[temp]][i];\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">else<\/span> Q.push(v);\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">if<\/span>(temp!=<span class=\"number\" style=\"color: #009999;\">0<\/span>)fail[v]=next[fail[temp]][i];\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">if<\/span>(num[next[fail[temp]][i]])num[next[temp][i]]++;\r\n}\r\n}\r\n}\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> vis[maxn];\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">bool<\/span> dfs(<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> now)\r\n{\r\nvis[now]=<span class=\"number\" style=\"color: #009999;\">1<\/span>;\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">for<\/span>(<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> j=<span class=\"number\" style=\"color: #009999;\">0<\/span>;j&lt;max_next;j++)\r\n{\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">if<\/span>(num[next[now][j]])<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">continue<\/span>;\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">if<\/span>(vis[next[now][j]]==<span class=\"number\" style=\"color: #009999;\">1<\/span>)<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">return<\/span> <span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">true<\/span>;\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">if<\/span>(vis[next[now][j]]==<span class=\"number\" style=\"color: #009999;\">0<\/span> &amp;&amp; dfs(next[now][j]))<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">return<\/span> <span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">true<\/span>;\r\n}\r\nvis[now]=-<span class=\"number\" style=\"color: #009999;\">1<\/span>;\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">return<\/span> <span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">false<\/span>;\r\n}\r\n\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">char<\/span> word[<span class=\"number\" style=\"color: #009999;\">30005<\/span>];\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> main()\r\n{\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> n,L;\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">while<\/span>(scanf(<span class=\"string\" style=\"color: #dd1144;\">\"%d\"<\/span>,&amp;n)!=EOF)\r\n{\r\ninit();\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">for<\/span>(<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> i=<span class=\"number\" style=\"color: #009999;\">1<\/span>;i&lt;=n;i++)\r\n{\r\nscanf(<span class=\"string\" style=\"color: #dd1144;\">\"%s\"<\/span>,word);\r\nInsert(word,strlen(word));\r\n}\r\nacbuild();\r\nmemset(vis,<span class=\"number\" style=\"color: #009999;\">0<\/span>,<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">sizeof<\/span> vis);\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">bool<\/span> ans=<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">false<\/span>;\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">for<\/span>(<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">int<\/span> i=<span class=\"number\" style=\"color: #009999;\">0<\/span>;i&lt;siz;i++)\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">if<\/span>(!vis[i] &amp;&amp; dfs(i))\r\n{\r\nans=<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">true<\/span>;\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">break<\/span>;\r\n}\r\nacdebug();\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">if<\/span>(ans)puts(<span class=\"string\" style=\"color: #dd1144;\">\"TAK\\n\"<\/span>);\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">else<\/span> puts(<span class=\"string\" style=\"color: #dd1144;\">\"NIE\\n\"<\/span>);\r\n}\r\n<span class=\"keyword\" style=\"color: #333333; font-weight: bold;\">return<\/span> <span class=\"number\" style=\"color: #009999;\">0<\/span>;\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u75c5\u6bd2 Time Limit:\u00a0\u00a01000ms,\u00a0\u00a0Special Time Limit:\u00a02500ms,\u00a0\u00a0M &#8230; <a title=\"Hnu 10104 \u75c5\u6bd2 (AC\u81ea\u52a8\u673a+dfs)\" class=\"read-more\" href=\"https:\/\/wx.wosign.com\/?p=1213\" aria-label=\"More on Hnu 10104 \u75c5\u6bd2 (AC\u81ea\u52a8\u673a+dfs)\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/wx.wosign.com\/index.php?rest_route=\/wp\/v2\/posts\/1213"}],"collection":[{"href":"https:\/\/wx.wosign.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wx.wosign.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wx.wosign.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/wx.wosign.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1213"}],"version-history":[{"count":1,"href":"https:\/\/wx.wosign.com\/index.php?rest_route=\/wp\/v2\/posts\/1213\/revisions"}],"predecessor-version":[{"id":1214,"href":"https:\/\/wx.wosign.com\/index.php?rest_route=\/wp\/v2\/posts\/1213\/revisions\/1214"}],"wp:attachment":[{"href":"https:\/\/wx.wosign.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wx.wosign.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wx.wosign.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}