{"id":129,"date":"2010-08-10T08:36:06","date_gmt":"2010-08-10T00:36:06","guid":{"rendered":"http:\/\/www.shuizilong.com\/house\/?p=129"},"modified":"2012-03-03T19:36:02","modified_gmt":"2012-03-03T11:36:02","slug":"hoj-1844-how-many-answers-are-wrong","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/house\/archives\/hoj-1844-how-many-answers-are-wrong\/","title":{"rendered":"HOJ 1844. How Many Answers Are Wrong"},"content":{"rendered":"<h3>Brief description :<\/h3>\n<p>\u52a8\u6001\u7ef4\u62a4\u4e00\u7ec4\u63cf\u8ff0\uff0c\u6bcf\u4e00\u4e2a\u6761\u76ee\u8868\u793a\u533a\u95f4 [l, r] \u5185\u4e00\u5171\u6709 s \u4e2a\u77f3\u5b50\u3002<br \/>\n\u5982\u679c\u540c\u524d\u9762\u7684\u63cf\u8ff0\u77db\u76fe\u5219\u5ffd\u7565\uff0c\u7edf\u8ba1\u6240\u6709\u77db\u76fe\u63cf\u8ff0\u7684\u603b\u6570\u3002<br \/>\n<!--more--><\/p>\n<h3>Analyse :<\/h3>\n<p>\u8bbe\u8ba1\u4e00\u7ec4\u5e76\u67e5\u96c6\uff0c\u5c06\u6240\u6709\u53ef\u4ee5\u8ba1\u7b97\u51fa\u7b54\u6848\u7684\u70b9\u7528\u5408\u5e76\u8d77\u6765\uff0c\u6839\u7ed3\u70b9\u653e\u518d\u6700\u5de6\u8fb9\uff0c\u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u8be2\u95ee\u5982\u679c\u5728\u4e00\u4e2a\u96c6\u5408\u4e2d\u5219\u67e5\u8be2 S[r].s &#8211; S[l].s \u5373\u53ef\u3002<br \/>\n&#8230;<br \/>\n\u81f3\u4e8e\u7ef4\u62a4\u7684\u90e8\u5206\uff0c\u9700\u8981\u753b\u56fe\u3002\uff08\u6ce8\u610f\u8003\u5bdf\u6709\u5411\u7ebf\u6bb5\uff0c\u6216\u8005\u76f4\u63a5\u5199\u4e00\u79cd\u60c5\u51b5\u7136\u540e\u53e6\u4e00\u79cd\u60c5\u51b5\u53d6\u53cd\u76f4\u63a5\u5199\u4e5f\u884c\u3002\u3002\uff09<\/p>\n<pre lang=\"cpp\">\r\n#include <iostream>\r\nusing namespace std;\r\n\r\nconst int N = 200001;\r\n\r\nstruct ufs{\r\n    int p, s;\r\n} S[N];\r\n\r\nint l, ll, r, rr, s;\r\nint n, m;\r\nint ans;\r\n\r\n\r\nvoid Make(int x){\r\n    S[x].p = x; S[x].s = 0;\r\n}\r\n\r\nint Find(int x){\r\n    if (S[x].p!=x) {\r\n        int p = S[x].p;\r\n        S[x].p = Find(p);\r\n        S[x].s += S[p].s;\r\n    }\r\n    return S[x].p;\r\n}\r\n\r\nvoid Union(int x, int y, int s){\r\n    S[x].s = s;\r\n    S[x].p = y;\r\n}\r\n\r\n\r\n\r\nint main(){\r\n    while (cin >> n >> m){\r\n        ans = 0;\r\n        for (int i=0;i<=n;i++)\r\n            Make(i);\r\n\r\n        for (int i=0;i<m;i++){\r\n            cin >> l >> r >> s; l--;\r\n            ll = S[Find(l)].p; rr = S[Find(r)].p;\r\n\r\n            if (ll==rr){\r\n                if (S[r].s-S[l].s!=s) ans++;\r\n            }\r\n            else {\r\n                if (ll<rr){\r\n                    Union(rr, l, s - S[r].s);\r\n                }\r\n                else{\r\n                    s = -s;\r\n                    Union(ll, r, s - S[l].s);\r\n                }\r\n            }\r\n        }\r\n        cout << ans << endl;\r\n    }\r\n\r\n}\r\n<\/pre>\n<p><\/bk><br \/>\n<\/bk><\/p>\n<h3>External link :<\/h3>\n<p>\u7ecf\u5178\u5e76\u67e5\u9898... \u4f60\u53ef\u4ee5\u5728\u5f88\u591a\u5730\u65b9\u627e\u5230\u7c7b\u4f3c\u601d\u60f3\u7684\u9898\u76ee\u63d0\u4ea4\u3002<br \/>\nhttp:\/\/acm.hit.edu.cn\/judge\/show.php?Proid=2844<br \/>\nhttp:\/\/hi.baidu.com\/%D3%EE%D6%C7%B2%A8%B4%F8%B9%B7\/blog\/item\/be3030e7dec85526b938209b.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Brief description : \u52a8\u6001\u7ef4\u62a4\u4e00\u7ec4\u63cf\u8ff0\uff0c\u6bcf\u4e00\u4e2a\u6761\u76ee\u8868\u793a\u533a\u95f4 [l, r] \u5185\u4e00\u5171\u6709 s \u4e2a\u77f3\u5b50\u3002 \u5982\u679c\u540c\u524d\u9762\u7684\u63cf\u8ff0\u77db\u76fe\u5219\u5ffd\u7565\uff0c\u7edf\u8ba1\u6240\u6709\u77db\u76fe\u63cf\u8ff0\u7684\u603b\u6570\u3002<\/p>\n","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":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"class_list":["post-129","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2tdP7-25","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/129","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=129"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/posts\/129\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/media?parent=129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/categories?post=129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/house\/wp-json\/wp\/v2\/tags?post=129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}