{"id":141,"date":"2021-01-02T15:44:00","date_gmt":"2021-01-02T15:44:00","guid":{"rendered":"https:\/\/imwarming.com\/?p=141"},"modified":"2021-01-02T15:44:00","modified_gmt":"2021-01-02T15:44:00","slug":"pta1126eulerianpath","status":"publish","type":"post","link":"https:\/\/imwarming.com\/?p=141","title":{"rendered":"PTA 1126 Eulerian Path"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img2020.cnblogs.com\/blog\/1634852\/202101\/1634852-20210102233420592-145494938.png\" alt=\"\" loading=\"lazy\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u65e0\u5411\u8fde\u901a\u56fe\uff0c\u8f93\u51fa\u6bcf\u4e2a\u9876\u70b9\u7684\u5ea6\u5e76\u5224\u65adeulerian\u3001semi-eulerian\u548cnon-eulerian\u8fd93\u79cd\u60c5\u51b5\uff0c\u6211\u4eec\u76f4\u63a5\u8bb0\u5f55\u6bcf\u4e2a\u70b9\u6240\u8fde\u63a5\u7684\u70b9\uff0c\u8fd9\u6837\u76f4\u63a5\u5f97\u5230\u5b83\u7684\u5ea6\uff0c\u7136\u540e\u5229\u7528\u6df1\u5ea6\u4f18\u5148\u548cvisit\u6570\u7ec4\u6765\u5224\u65ad\u56fe\u662f\u5426\u8fde\u901a\uff0c\u4e0d\u8fde\u901a\u76f4\u63a5\u662fnon-eulerian\u60c5\u51b5\uff0c\u8fde\u901a\u7684\u8bdd\u518d\u5224\u65ad\u9876\u70b9\u7684\u5ea6\u662f\u5426\u90fd\u662f\u5076\u6570\uff0c\u662f\u7684\u8bdd\u5c31\u662feulerian\u60c5\u51b5\uff0c\u4e0d\u662f\u7684\u8bdd\u518d\u5224\u65ad\u5b83\u5947\u6570\u5ea6\u7684\u4e2a\u6570\u662f\u5426\u4e3a2\u4e2a\uff0c\u4e5f\u5c31\u662f\u5076\u6570\u6bd4\u603b\u9876\u70b9\u6570\u5c112\u4e2a\uff0c\u662f\u7684\u8bdd\u5c31\u662f\u5c31\u662fsemi-eulerian\u60c5\u51b5\u4e86\u3002<\/p>\n<div class=\"cnblogs_code\">\n<pre>#include&lt;bits\/stdc++.h&gt;\n\n<span style=\"color: #0000ff;\">using<\/span> <span style=\"color: #0000ff;\">namespace<\/span><span style=\"color: #000000;\"> std;\ntypedef <\/span><span style=\"color: #0000ff;\">long<\/span> <span style=\"color: #0000ff;\">long<\/span><span style=\"color: #000000;\"> ll;\n<\/span><span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #0000ff;\">int<\/span> maxn =<span style=\"color: #000000;\"> 1e9;\n<\/span><span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #0000ff;\">int<\/span> maxm = 1e5 + <span style=\"color: #800080;\">5<\/span><span style=\"color: #000000;\">;\n<\/span><span style=\"color: #0000ff;\">const<\/span> ll inf = <span style=\"color: #800080;\">2147483647<\/span><span style=\"color: #000000;\">;\n<\/span><span style=\"color: #0000ff;\">using<\/span> <span style=\"color: #0000ff;\">namespace<\/span><span style=\"color: #000000;\"> std;\nvector<\/span>&lt;<span style=\"color: #0000ff;\">int<\/span>&gt; v[<span style=\"color: #800080;\">505<\/span><span style=\"color: #000000;\">];\n<\/span><span style=\"color: #0000ff;\">int<\/span> visit[<span style=\"color: #800080;\">505<\/span><span style=\"color: #000000;\">];\n\n<\/span><span style=\"color: #0000ff;\">void<\/span> dfs(<span style=\"color: #0000ff;\">int<\/span><span style=\"color: #000000;\"> x) {\n    <\/span><span style=\"color: #0000ff;\">if<\/span> (visit[x] == <span style=\"color: #800080;\">0<\/span><span style=\"color: #000000;\">) {\n        visit[x] <\/span>= <span style=\"color: #800080;\">1<\/span><span style=\"color: #000000;\">;\n        <\/span><span style=\"color: #0000ff;\">for<\/span> (<span style=\"color: #0000ff;\">int<\/span> i = <span style=\"color: #800080;\">0<\/span>; i &lt; v[x].size(); i++<span style=\"color: #000000;\">) {\n            dfs(v[x][i]);\n        }\n    }\n}\n\n<\/span><span style=\"color: #0000ff;\">int<\/span><span style=\"color: #000000;\"> main() {\n    <\/span><span style=\"color: #0000ff;\">int<\/span><span style=\"color: #000000;\"> n, m;\n    cin <\/span>&gt;&gt; n &gt;&gt;<span style=\"color: #000000;\"> m;\n    <\/span><span style=\"color: #0000ff;\">int<\/span><span style=\"color: #000000;\"> a, b;\n    <\/span><span style=\"color: #0000ff;\">for<\/span> (<span style=\"color: #0000ff;\">int<\/span> i = <span style=\"color: #800080;\">0<\/span>; i &lt; m; i++<span style=\"color: #000000;\">) {\n        cin <\/span>&gt;&gt; a &gt;&gt;<span style=\"color: #000000;\"> b;\n        v[a].push_back(b);\n        v[b].push_back(a);\n    }\n    <\/span><span style=\"color: #0000ff;\">int<\/span> sum = <span style=\"color: #800080;\">0<\/span><span style=\"color: #000000;\">;\n    cout <\/span>&lt;&lt; v[<span style=\"color: #800080;\">1<\/span><span style=\"color: #000000;\">].size();\n    <\/span><span style=\"color: #0000ff;\">if<\/span> (v[<span style=\"color: #800080;\">1<\/span>].size() % <span style=\"color: #800080;\">2<\/span> == <span style=\"color: #800080;\">0<\/span>)sum++<span style=\"color: #000000;\">;\n    <\/span><span style=\"color: #0000ff;\">for<\/span> (<span style=\"color: #0000ff;\">int<\/span> i = <span style=\"color: #800080;\">2<\/span>; i &lt;= n; i++<span style=\"color: #000000;\">) {\n        cout <\/span>&lt;&lt; <span style=\"color: #800000;\">'<\/span> <span style=\"color: #800000;\">'<\/span> &lt;&lt;<span style=\"color: #000000;\"> v[i].size();\n        <\/span><span style=\"color: #0000ff;\">if<\/span> (v[i].size() % <span style=\"color: #800080;\">2<\/span> == <span style=\"color: #800080;\">0<\/span><span style=\"color: #000000;\">)\n            sum<\/span>++<span style=\"color: #000000;\">;\n    }\n    cout <\/span>&lt;&lt; <span style=\"color: #800000;\">\"<\/span><span style=\"color: #800000;\">n<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #000000;\">;\n    dfs(<\/span><span style=\"color: #800080;\">1<\/span><span style=\"color: #000000;\">);\n    <\/span><span style=\"color: #0000ff;\">int<\/span> f = <span style=\"color: #800080;\">1<\/span><span style=\"color: #000000;\">;\n    <\/span><span style=\"color: #0000ff;\">for<\/span> (<span style=\"color: #0000ff;\">int<\/span> i = <span style=\"color: #800080;\">1<\/span>; i &lt;= n; i++<span style=\"color: #000000;\">) {\n        <\/span><span style=\"color: #0000ff;\">if<\/span> (visit[i] == <span style=\"color: #800080;\">0<\/span><span style=\"color: #000000;\">)\n            f <\/span>= <span style=\"color: #800080;\">0<\/span><span style=\"color: #000000;\">;\n    }\n    <\/span><span style=\"color: #0000ff;\">if<\/span> (!<span style=\"color: #000000;\">f) {\n        cout <\/span>&lt;&lt; <span style=\"color: #800000;\">\"<\/span><span style=\"color: #800000;\">non-eulerian<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #000000;\">;\n        <\/span><span style=\"color: #0000ff;\">return<\/span> <span style=\"color: #800080;\">0<\/span><span style=\"color: #000000;\">;\n    }\n    <\/span><span style=\"color: #0000ff;\">if<\/span> (sum ==<span style=\"color: #000000;\"> n)\n        cout <\/span>&lt;&lt; <span style=\"color: #800000;\">\"<\/span><span style=\"color: #800000;\">eulerian<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #000000;\">;\n    <\/span><span style=\"color: #0000ff;\">else<\/span> <span style=\"color: #0000ff;\">if<\/span> (sum == n - <span style=\"color: #800080;\">2<\/span><span style=\"color: #000000;\">)\n        cout <\/span>&lt;&lt; <span style=\"color: #800000;\">\"<\/span><span style=\"color: #800000;\">semi-eulerian<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #000000;\">;\n    <\/span><span style=\"color: #0000ff;\">else<\/span> cout &lt;&lt; <span style=\"color: #800000;\">\"<\/span><span style=\"color: #800000;\">non-eulerian<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #000000;\">;\n    <\/span><span style=\"color: #0000ff;\">return<\/span> <span style=\"color: #800080;\">0<\/span><span style=\"color: #000000;\">;\n}<\/span><\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u65e0\u5411\u8fde\u901a\u56fe\uff0c\u8f93\u51fa\u6bcf\u4e2a\u9876\u70b9\u7684\u5ea6\u5e76\u5224\u65adeulerian\u3001semi-eulerian\u548cnon [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-141","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PTA 1126 Eulerian Path - imwarming<\/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:\/\/imwarming.com\/?p=141\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PTA 1126 Eulerian Path - imwarming\" \/>\n<meta property=\"og:description\" content=\"&nbsp; \u65e0\u5411\u8fde\u901a\u56fe\uff0c\u8f93\u51fa\u6bcf\u4e2a\u9876\u70b9\u7684\u5ea6\u5e76\u5224\u65adeulerian\u3001semi-eulerian\u548cnon [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/imwarming.com\/?p=141\" \/>\n<meta property=\"og:site_name\" content=\"imwarming\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-02T15:44:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/img2020.cnblogs.com\/blog\/1634852\/202101\/1634852-20210102233420592-145494938.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"warming\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/imwarming.com\/#website\",\"url\":\"https:\/\/imwarming.com\/\",\"name\":\"imwarming\",\"description\":\"\u6c38\u8fdc\u5e74\u8f7b\uff0c\u6c38\u8fdc\u70ed\u6cea\u76c8\u7736\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/imwarming.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/imwarming.com\/?p=141#primaryimage\",\"inLanguage\":\"zh-Hans\",\"url\":\"https:\/\/img2020.cnblogs.com\/blog\/1634852\/202101\/1634852-20210102233420592-145494938.png\",\"contentUrl\":\"https:\/\/img2020.cnblogs.com\/blog\/1634852\/202101\/1634852-20210102233420592-145494938.png\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/imwarming.com\/?p=141#webpage\",\"url\":\"https:\/\/imwarming.com\/?p=141\",\"name\":\"PTA 1126 Eulerian Path - imwarming\",\"isPartOf\":{\"@id\":\"https:\/\/imwarming.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/imwarming.com\/?p=141#primaryimage\"},\"datePublished\":\"2021-01-02T15:44:00+00:00\",\"dateModified\":\"2021-01-02T15:44:00+00:00\",\"author\":{\"@id\":\"https:\/\/imwarming.com\/#\/schema\/person\/9d76869a558bac6dd0d6d58f420ee8ea\"},\"breadcrumb\":{\"@id\":\"https:\/\/imwarming.com\/?p=141#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/imwarming.com\/?p=141\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/imwarming.com\/?p=141#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/imwarming.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PTA 1126 Eulerian Path\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/imwarming.com\/#\/schema\/person\/9d76869a558bac6dd0d6d58f420ee8ea\",\"name\":\"warming\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/imwarming.com\/#personlogo\",\"inLanguage\":\"zh-Hans\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c4a913eed88f7601b76bbf2b103472621195b6fa2f742af89b5ea185b60e7cff?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c4a913eed88f7601b76bbf2b103472621195b6fa2f742af89b5ea185b60e7cff?s=96&d=mm&r=g\",\"caption\":\"warming\"},\"sameAs\":[\"https:\/\/imwarming.com\"],\"url\":\"https:\/\/imwarming.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PTA 1126 Eulerian Path - imwarming","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:\/\/imwarming.com\/?p=141","og_locale":"zh_CN","og_type":"article","og_title":"PTA 1126 Eulerian Path - imwarming","og_description":"&nbsp; \u65e0\u5411\u8fde\u901a\u56fe\uff0c\u8f93\u51fa\u6bcf\u4e2a\u9876\u70b9\u7684\u5ea6\u5e76\u5224\u65adeulerian\u3001semi-eulerian\u548cnon [&hellip;]","og_url":"https:\/\/imwarming.com\/?p=141","og_site_name":"imwarming","article_published_time":"2021-01-02T15:44:00+00:00","og_image":[{"url":"https:\/\/img2020.cnblogs.com\/blog\/1634852\/202101\/1634852-20210102233420592-145494938.png"}],"twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"warming","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/imwarming.com\/#website","url":"https:\/\/imwarming.com\/","name":"imwarming","description":"\u6c38\u8fdc\u5e74\u8f7b\uff0c\u6c38\u8fdc\u70ed\u6cea\u76c8\u7736","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/imwarming.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"ImageObject","@id":"https:\/\/imwarming.com\/?p=141#primaryimage","inLanguage":"zh-Hans","url":"https:\/\/img2020.cnblogs.com\/blog\/1634852\/202101\/1634852-20210102233420592-145494938.png","contentUrl":"https:\/\/img2020.cnblogs.com\/blog\/1634852\/202101\/1634852-20210102233420592-145494938.png"},{"@type":"WebPage","@id":"https:\/\/imwarming.com\/?p=141#webpage","url":"https:\/\/imwarming.com\/?p=141","name":"PTA 1126 Eulerian Path - imwarming","isPartOf":{"@id":"https:\/\/imwarming.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/imwarming.com\/?p=141#primaryimage"},"datePublished":"2021-01-02T15:44:00+00:00","dateModified":"2021-01-02T15:44:00+00:00","author":{"@id":"https:\/\/imwarming.com\/#\/schema\/person\/9d76869a558bac6dd0d6d58f420ee8ea"},"breadcrumb":{"@id":"https:\/\/imwarming.com\/?p=141#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/imwarming.com\/?p=141"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/imwarming.com\/?p=141#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/imwarming.com\/"},{"@type":"ListItem","position":2,"name":"PTA 1126 Eulerian Path"}]},{"@type":"Person","@id":"https:\/\/imwarming.com\/#\/schema\/person\/9d76869a558bac6dd0d6d58f420ee8ea","name":"warming","image":{"@type":"ImageObject","@id":"https:\/\/imwarming.com\/#personlogo","inLanguage":"zh-Hans","url":"https:\/\/secure.gravatar.com\/avatar\/c4a913eed88f7601b76bbf2b103472621195b6fa2f742af89b5ea185b60e7cff?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c4a913eed88f7601b76bbf2b103472621195b6fa2f742af89b5ea185b60e7cff?s=96&d=mm&r=g","caption":"warming"},"sameAs":["https:\/\/imwarming.com"],"url":"https:\/\/imwarming.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/imwarming.com\/index.php?rest_route=\/wp\/v2\/posts\/141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imwarming.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imwarming.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imwarming.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/imwarming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=141"}],"version-history":[{"count":0,"href":"https:\/\/imwarming.com\/index.php?rest_route=\/wp\/v2\/posts\/141\/revisions"}],"wp:attachment":[{"href":"https:\/\/imwarming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imwarming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imwarming.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}