{"id":139,"date":"2012-08-13T18:45:00","date_gmt":"2012-08-13T10:45:00","guid":{"rendered":"http:\/\/nike0good.jp1.rpvhost.net\/27"},"modified":"2012-08-13T18:45:00","modified_gmt":"2012-08-13T10:45:00","slug":"poj_1094_topological_sorting","status":"publish","type":"post","link":"https:\/\/nike0good.com\/?p=139","title":{"rendered":"POJ 1094(\u62d3\u6251\u6392\u5e8f\uff09"},"content":{"rendered":"<p>\u62d3\u6392&#43;\u5404\u79cd\u5224\u2026\u2026<\/p>\n<p>\n<\/p>\n<p><pre name=\"code\" class=\"delphi\">Program P1094;\ntype\n   map3=record\n        indegree:array['A'..'Z'] of longint;\n        map:array['A'..'Z',1..26] of char;\n        outdegree:array['A'..'Z'] of longint;\n        end;\nvar\n   n,m,i,j,num,value,topvalue:longint;\n   s:string;\n   topout:string;\n   map,map2:map3;\n   mark:array['A'..'Z'] of boolean;\n   tag:boolean;\nFunction topsort:longint;\nvar\n   j,k,h,s,zero:longint;\n   flag:boolean;\n   i:char;\nbegin\n   topsort:=3;\n   topout:='';\n   flag:=false;\n   h:=1;\n   s:=0;\n   zero:=0;\n   for i:='A' to 'Z' do if mark[i] then if map2.indegree[i]=0 then begin inc(zero); topout:=topout+i; end;\n   if zero=0 then exit(2);\n   s:=length(topout);\n   while (h&lt;=s) do\n   begin\n      if (h&lt;s) then flag:=true;\n      for j:=h to s do\n      begin\n         for k:=1 to map2.outdegree[topout[j]] do\n         begin\n            dec(map2.indegree[map2.map[topout[j],k]]);\n            if map2.indegree[map2.map[topout[j],k]]=0 then\n            begin\n               topout:=topout+map2.map[topout[j],k];\n            end;\n         end;\n         if length(topout)&gt;num then exit(2);\n      end;\n      h:=s+1;\n      s:=length(topout);\n   end;\n   if s&lt;num then exit(2);\n   if (s=num) and (num&lt;n) then exit(3);\n\n   if flag or (num&lt;n) then exit(3) else exit(1);\n\nend;\nProcedure ski(step:longint);\nvar\n   i:longint;\n   s:string;\nbegin\n   for i:=step+1 to m do readln(s);\nend;\nProcedure pri(value,step:longint);\nbegin\n   if value=1 then writeln('Sorted sequence determined after ',step,' relations: ',topout,'.');\n   if value=3 then writeln('Sorted sequence cannot be determined.');\n   if value=2 then\n   begin\n      writeln('Inconsistency found after ',step,' relations.');\n      ski(step);\n   end;\n   if value=1 then ski(step);\nend;\n\nbegin\n {  assign(input,'P1094.in');\n   assign(output,'p1094.out');\n   reset(input);\n   rewrite(output);    }\n   readln(n,m);\n   while (n+m&gt;0) do\n   begin\n      topout:='';\n      fillchar(map,sizeof(map),0);\n      fillchar(mark,sizeof(mark),false);\n      num:=0;\n      value:=3;\n      for i:=1 to m do\n      begin\n         readln(s);\n         if (ord('A')-1+n&lt;ord(s[1])) or (ord('A')-1+n&lt;ord(s[3])) or (s[1]=s[3]) then\n         begin\n            value:=2;\n            break;\n         end;\n\n         if not(mark[s[1]]) then begin mark[s[1]]:=true; inc(num); end;\n         if not(mark[s[3]]) then begin mark[s[3]]:=true; inc(num); end;\n         tag:=false;\n         for j:=1 to map.outdegree[s[1]] do\n            if map.map[s[1],j]=s[3] then begin tag:=true; break; end;\n         if tag then continue;\n         inc(map.indegree[s[3]]);\n         inc(map.outdegree[s[1]]);\n         map.map[s[1],map.outdegree[s[1]]]:=s[3];\n\n         map2:=map;\n         topvalue:=topsort;\n         if topvalue&lt;=2 then begin value:=topvalue; break; end;\n      end;\n      pri(value,i);\n      readln(n,m);\n   end;\n{   close(input);\n   close(output);  }\nend.<\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u62d3\u6392&#43;\u5404\u79cd\u5224\u2026\u2026 Program P1094; type map3=record indegree:a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"categories":[3],"tags":[65],"class_list":["post-139","post","type-post","status-publish","format-standard","hentry","category-defaultcategory","tag-graph_theory"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>POJ 1094(\u62d3\u6251\u6392\u5e8f\uff09 - nike0good<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/nike0good.com\/?p=139\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"POJ 1094(\u62d3\u6251\u6392\u5e8f\uff09 - nike0good\" \/>\n<meta property=\"og:description\" content=\"\u62d3\u6392&#043;\u5404\u79cd\u5224\u2026\u2026 Program P1094; type map3=record indegree:a [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nike0good.com\/?p=139\" \/>\n<meta property=\"og:site_name\" content=\"nike0good\" \/>\n<meta property=\"article:published_time\" content=\"2012-08-13T10:45:00+00:00\" \/>\n<meta name=\"author\" content=\"nike0good\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"nike0good\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=139#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=139\"},\"author\":{\"name\":\"nike0good\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\"},\"headline\":\"POJ 1094(\u62d3\u6251\u6392\u5e8f\uff09\",\"datePublished\":\"2012-08-13T10:45:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=139\"},\"wordCount\":1,\"commentCount\":0,\"keywords\":[\"\u56fe\u8bba\"],\"articleSection\":[\"DefaultCategory\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/nike0good.com\\\/?p=139#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=139\",\"url\":\"https:\\\/\\\/nike0good.com\\\/?p=139\",\"name\":\"POJ 1094(\u62d3\u6251\u6392\u5e8f\uff09 - nike0good\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/#website\"},\"datePublished\":\"2012-08-13T10:45:00+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=139#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/nike0good.com\\\/?p=139\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=139#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/nike0good.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"POJ 1094(\u62d3\u6251\u6392\u5e8f\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#website\",\"url\":\"https:\\\/\\\/nike0good.com\\\/\",\"name\":\"nike0good\",\"description\":\"\u6709\u6240\u4f5c\u4e3a\u662f\u4eba\u751f\u7684\u6700\u9ad8\u5883\u754c\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/nike0good.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\",\"name\":\"nike0good\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"caption\":\"nike0good\"},\"sameAs\":[\"https:\\\/\\\/nike0good.com\"],\"url\":\"https:\\\/\\\/nike0good.com\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"POJ 1094(\u62d3\u6251\u6392\u5e8f\uff09 - nike0good","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/nike0good.com\/?p=139","og_locale":"zh_CN","og_type":"article","og_title":"POJ 1094(\u62d3\u6251\u6392\u5e8f\uff09 - nike0good","og_description":"\u62d3\u6392&#43;\u5404\u79cd\u5224\u2026\u2026 Program P1094; type map3=record indegree:a [&hellip;]","og_url":"https:\/\/nike0good.com\/?p=139","og_site_name":"nike0good","article_published_time":"2012-08-13T10:45:00+00:00","author":"nike0good","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"nike0good","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/nike0good.com\/?p=139#article","isPartOf":{"@id":"https:\/\/nike0good.com\/?p=139"},"author":{"name":"nike0good","@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad"},"headline":"POJ 1094(\u62d3\u6251\u6392\u5e8f\uff09","datePublished":"2012-08-13T10:45:00+00:00","mainEntityOfPage":{"@id":"https:\/\/nike0good.com\/?p=139"},"wordCount":1,"commentCount":0,"keywords":["\u56fe\u8bba"],"articleSection":["DefaultCategory"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/nike0good.com\/?p=139#respond"]}]},{"@type":"WebPage","@id":"https:\/\/nike0good.com\/?p=139","url":"https:\/\/nike0good.com\/?p=139","name":"POJ 1094(\u62d3\u6251\u6392\u5e8f\uff09 - nike0good","isPartOf":{"@id":"https:\/\/nike0good.com\/#website"},"datePublished":"2012-08-13T10:45:00+00:00","author":{"@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad"},"breadcrumb":{"@id":"https:\/\/nike0good.com\/?p=139#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nike0good.com\/?p=139"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/nike0good.com\/?p=139#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/nike0good.com\/"},{"@type":"ListItem","position":2,"name":"POJ 1094(\u62d3\u6251\u6392\u5e8f\uff09"}]},{"@type":"WebSite","@id":"https:\/\/nike0good.com\/#website","url":"https:\/\/nike0good.com\/","name":"nike0good","description":"\u6709\u6240\u4f5c\u4e3a\u662f\u4eba\u751f\u7684\u6700\u9ad8\u5883\u754c","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nike0good.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad","name":"nike0good","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","caption":"nike0good"},"sameAs":["https:\/\/nike0good.com"],"url":"https:\/\/nike0good.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts\/139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=139"}],"version-history":[{"count":0,"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts\/139\/revisions"}],"wp:attachment":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}