{"id":70,"date":"2016-09-21T17:19:13","date_gmt":"2016-09-21T09:19:13","guid":{"rendered":"http:\/\/tyswly.com\/?p=70"},"modified":"2016-09-21T17:19:13","modified_gmt":"2016-09-21T09:19:13","slug":"%e4%b8%ad%e7%a7%8b%e5%a4%a7%e7%a4%bc%e5%8c%85%e5%b0%8fl%e7%9a%84%e5%91%98%e5%b7%a5","status":"publish","type":"post","link":"https:\/\/tys.fun\/?p=70","title":{"rendered":"[\u4e2d\u79cb\u5927\u793c\u5305]\u5c0fL\u7684\u5458\u5de5"},"content":{"rendered":"<p>\u4e2d\u79cb\u8282\u5f31\u6821\u7684\u4e00\u573a\u5c0f\u6bd4\u8d5b\u7684\u7b2c\u4e8c\u9898\u3002\u3002<a href=\"http:\/\/syzoj.com\/contest\/25\">SYZOJ<\/a><br \/>\n\u8fd9\u662f\u7b2c\u4e8c\u9898\uff0c\u5178\u578b\u7684\u62d3\u6251\u6392\u5e8f\uff0c\u53ea\u662f\u9700\u8981\u6dfb\u52a0\u4e00\u4e2a\u4f18\u5148\u961f\u5217\u6765\u4fdd\u8bc1\u8f93\u51fa\u6ee1\u8db3\u5b57\u5178\u5e8f\u3002<br \/>\n\u9898\u6bd4\u8f83\u6c34\uff0c\u76f4\u63a5\u8d34\u4ee3\u7801\u4e86\u3002<\/p>\n<pre class=\"font-size-enable:false lang:c++ decode:true \">#include &lt;iostream&gt;\n#include &lt;cstdio&gt;\n#include &lt;algorithm&gt;\n#include &lt;queue&gt;\nusing namespace std;\nconst int MX = 1e5 + 5;\nint n, m, head[MX], tot, cnt, in[MX];\nint ans[MX];\nbool vis[MX];\nstruct edge{\n\tint fr, to, ne;\n}e[1000005];\npriority_queue&lt;int, vector&lt;int&gt;, greater&lt;int&gt; &gt; q;\nvoid addedge(int a, int b) {\n\ttot++;\n\te[tot].fr = a;\n\te[tot].to = b;\n\te[tot].ne = head[a];\n\thead[a] = tot;\n}\nvoid bfs() {\n\tfor (int i = 1; i &lt;= n; i++) {\n\t\tif (!in[i]) {\n\t\t\tq.push(i);\n\t\t}\n\t}\n\twhile (!q.empty()) {\n\t\tint now = q.top();\n\t\tans[++cnt] = now;\n\t\tq.pop();\n\t\tfor (int i = head[now]; i; i = e[i].ne) {\n\t\t\tint to = e[i].to;\n\t\t\tif (vis[to]) continue;\n\t\t\tin[to]--;\n\t\t\tif (in[to] != 0) continue;\n\t\t\tvis[to] = true;\n\t\t\tq.push(to);\n\t\t}\n\t}\n\tif (cnt == n) {\n\t\tfor (int i = 1; i &lt;= n; i++) {\n\t\t\tprintf(\"%d \", ans[i]);\n\t\t}\n\t\tprintf(\"\\n\");\n\t} else {\n\t\tprintf(\"-1\\n\");\n\t}\n}\nint main() {\n\tscanf(\"%d%d\", &amp;n, &amp;m);\n\tint x, y;\n\tfor (int i = 1; i &lt;= m; i++) {\n\t\tscanf(\"%d%d\", &amp;x, &amp;y);\n\t\tin[y]++;\n\t\taddedge(x, y);\n\t}\n\tbfs();\n\treturn 0;\n}\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e2d\u79cb\u8282\u5f31\u6821\u7684\u4e00\u573a\u5c0f\u6bd4\u8d5b\u7684\u7b2c\u4e8c\u9898\u3002\u3002SYZOJ \u8fd9\u662f\u7b2c\u4e8c\u9898\uff0c\u5178\u578b\u7684\u62d3\u6251\u6392\u5e8f\uff0c\u53ea\u662f\u9700\u8981\u6dfb\u52a0\u4e00\u4e2a\u4f18\u5148\u961f\u5217\u6765\u4fdd\u8bc1\u8f93\u51fa\u6ee1 &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-70","post","type-post","status-publish","format-standard","hentry","category-report"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/posts\/70","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tys.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=70"}],"version-history":[{"count":0,"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/posts\/70\/revisions"}],"wp:attachment":[{"href":"https:\/\/tys.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tys.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tys.fun\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}