{"id":1011,"date":"2014-10-05T02:32:25","date_gmt":"2014-10-04T18:32:25","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=1011"},"modified":"2014-10-05T16:27:37","modified_gmt":"2014-10-05T08:27:37","slug":"poj-3764-the-xor-longest-path","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/poj-3764-the-xor-longest-path\/","title":{"rendered":"POJ 3764. The xor-longest Path"},"content":{"rendered":"<p><!--more--><\/p>\n<h2>Problem 1008. Hilarity<\/h2>\n<h3>Brief description: <\/h3>\n<p>\u7ed9\u5b9a\u4e00\u9897\u8fb9\u6743\u6811\uff0c\u6c42\u4e00\u6761\u8def\u5f84\uff0c\u6700\u5927\u5316\u5f02\u6216\u548c\u3002<\/p>\n<h3>Analysis: <\/h3>\n<p>Tire + \u8d2a\u5fc3 \u3002\uff09<\/p>\n<p>\uff08\u8fb9\u8868\u7528 vector \u4f1a TLE\u3002\uff09<\/p>\n<p><a href=\"http:\/\/acm.hust.edu.cn\/vjudge\/problem\/viewSource.action?id=2815893\">http:\/\/acm.hust.edu.cn\/vjudge\/problem\/viewSource.action?id=2815893<\/a><\/p>\n<p>See also http:\/\/www.codechef.com\/viewsolution\/4993836<\/p>\n<pre class=\"brush: cpp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\r\n\/\/}\/* .................................................................................................................................. *\/\r\n\r\nconst int N = int(1e5) + 9, LV = 31;\r\nint n;\r\n\r\nvoid _r(int &amp;x){\r\n    x=reverse_bits(x); x&gt;&gt;=1;\r\n}\r\n\r\nnamespace T{\r\n\r\n    int trans&#x5B;N*LV]&#x5B;2];\r\n    int nn;\r\n\r\n    int new_node(){\r\n        RST(trans&#x5B;nn]);\r\n        return nn++;\r\n    }\r\n\r\n    #define v trans&#x5B;u]&#x5B;c]\r\n\r\n    void Insert(int x){\r\n        _r(x); int u = 0; REP(i, LV){\r\n            int c = x &amp; 1; x &gt;&gt;= 1;\r\n            if (!v) v = new_node();\r\n            u = v;\r\n        }\r\n    }\r\n    int Query(int x){\r\n        int z = 0, u = 0; _r(x); REP(i, LV){\r\n            int c = (x &amp; 1) ^ 1; x &gt;&gt;= 1; z &lt;&lt;= 1;\r\n            if (!v) c ^= 1; else z |= 1;\r\n            u = v;\r\n        }\r\n        return z;\r\n    }\r\n    void Init(){\r\n        nn = 0; new_node();\r\n    }\r\n};\r\n\r\n#define aa to&#x5B;i^1]\r\n#define bb to&#x5B;i]\r\n#define v bb\r\n#define w ww&#x5B;i\/2]\r\n\r\nconst int M = N*2;\r\nint hd&#x5B;N], suc&#x5B;M], to&#x5B;M], ww&#x5B;N];\r\nint Xor&#x5B;N], maxXor;\r\n\r\nvoid dfs(int u = 0, int p = -1){\r\n\r\n    T::Insert(Xor&#x5B;u]);\r\n    checkMax(maxXor, T::Query(Xor&#x5B;u]));\r\n\r\n    REP_G(i, u) if (v != p){\r\n        Xor&#x5B;v] = Xor&#x5B;u] ^ w;\r\n        dfs(v, u);\r\n    }\r\n}\r\n\r\n\r\nint main(){\r\n\r\n#ifndef ONLINE_JUDGE\r\n    freopen(&quot;in.txt&quot;, &quot;r&quot;, stdin);\r\n    \/\/freopen(&quot;out.txt&quot;, &quot;w&quot;, stdout);\r\n#endif\r\n\r\n    while (~scanf(&quot;%d&quot;, &amp;n)){\r\n\r\n        fill(hd, hd+n, 0); FOR_C(i, 2, n&lt;&lt;1){\r\n            RD(aa, bb, w);\r\n            suc&#x5B;i] = hd&#x5B;aa], hd&#x5B;aa] = i++;\r\n            suc&#x5B;i] = hd&#x5B;aa], hd&#x5B;aa] = i;\r\n        }\r\n\r\n        maxXor = 0; T::Init(); dfs();\r\n        OT(maxXor);\r\n    }\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-1011","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-gj","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1011","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/comments?post=1011"}],"version-history":[{"count":1,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1011\/revisions"}],"predecessor-version":[{"id":1013,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/1011\/revisions\/1013"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=1011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=1011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=1011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}