{"id":33,"date":"2022-06-04T10:52:00","date_gmt":"2022-06-04T02:52:00","guid":{"rendered":"http:\/\/ubuntu.tim-wcx.ltd\/wordpress\/index.php\/2022\/06\/04\/2020-08-11\/"},"modified":"2022-06-04T10:52:00","modified_gmt":"2022-06-04T02:52:00","slug":"2020-08-11","status":"publish","type":"post","link":"https:\/\/wordpress.tim-wcx.ltd\/index.php\/2022\/06\/04\/2020-08-11\/","title":{"rendered":"2020-08-11"},"content":{"rendered":"<p><svg  style=\"display: none;\">\n                        <path stroke-linecap=\"round\" d=\"M5,0 0,2.5 5,5z\" id=\"raphael-marker-block\" style=\"-webkit-tap-highlight-color: rgba(0, 0, 0, 0);\"><\/path>\n                    <\/svg><\/p>\n<p><a href=\"http:\/\/icpc.upc.edu.cn\/problem.php?id=14881\">http:\/\/icpc.upc.edu.cn\/problem.php?id=14881<\/a><\/p>\n<h5><a id=\"_1\"><\/a>\u9898\u76ee<\/h5>\n<p>14881: \u4f1a\u8bae<\/p>\n<h5><a id=\"_3\"><\/a>\u9898\u76ee\u63cf\u8ff0<\/h5>\n<p>\u6709\u4e00\u4e2a\u6751\u5e84\u5c45\u4f4f\u7740n\u4e2a\u6751\u6c11\uff0c\u6709n-1\u6761\u8def\u5f84\u4f7f\u5f97\u8fd9n\u4e2a\u6751\u6c11\u7684\u5bb6\u8054\u901a\uff0c\u6bcf\u6761\u8def\u5f84\u7684\u957f\u5ea6\u90fd\u4e3a1\u3002\u73b0\u5728\u6751\u957f\u5e0c\u671b\u5728\u67d0\u4e2a\u6751\u6c11\u5bb6\u4e2d\u53ec\u5f00\u4e00\u573a\u4f1a\u8bae\uff0c\u6751\u957f\u5e0c\u671b\u6240\u6709\u6751\u6c11\u5230\u4f1a\u8bae\u5730\u70b9\u7684\u8ddd\u79bb\u4e4b\u548c\u6700\u5c0f\uff0c\u90a3\u4e48\u6751\u957f\u5e94\u8be5\u8981\u628a\u4f1a\u8bae\u5730\u70b9\u8bbe\u7f6e\u5728\u54ea\u4e2a\u6751\u6c11\u7684\u5bb6\u4e2d\uff0c\u5e76\u4e14\u8fd9\u4e2a\u8ddd\u79bb\u603b\u548c\u6700\u5c0f\u662f\u591a\u5c11\uff1f\u82e5\u6709\u591a\u4e2a\u8282\u70b9\u90fd\u6ee1\u8db3\u6761\u4ef6\uff0c\u5219\u9009\u62e9\u8282\u70b9\u7f16\u53f7\u6700\u5c0f\u7684\u90a3\u4e2a\u70b9\u3002<\/p>\n<h5><a id=\"_5\"><\/a>\u8f93\u5165<\/h5>\n<p>\u7b2c\u4e00\u884c\u3002\u4e00\u4e2a\u6570n\uff0c\u8868\u793a\u6709n\u4e2a\u6751\u6c11\u3002<br \/> \u63a5\u4e0b\u6765n-1\u884c\uff0c\u6bcf\u884c\u4e24\u4e2a\u6570\u5b57a\u548cb\uff0c\u8868\u793a\u6751\u6c11a\u7684\u5bb6\u548c\u6751\u6c11b\u7684\u5bb6\u4e4b\u95f4\u5b58\u5728\u4e00\u6761\u8def\u5f84\u3002<\/p>\n<h5><a id=\"_9\"><\/a>\u8f93\u51fa<\/h5>\n<p>\u4e00\u884c\u8f93\u51fa\u4e24\u4e2a\u6570\u5b57x\u548cy<br \/> x\u8868\u793a\u6751\u957f\u5c06\u4f1a\u5728\u54ea\u4e2a\u6751\u6c11\u5bb6\u4e2d\u4e3e\u529e\u4f1a\u8bae<br \/> y\u8868\u793a\u8ddd\u79bb\u4e4b\u548c\u7684\u6700\u5c0f\u503c<\/p>\n<h5><a id=\"_14\"><\/a>\u6837\u4f8b\u8f93\u5165<\/h5>\n<pre><code>4\n1 2\n2 3\n3 4\n<\/code><\/pre>\n<h5><a id=\"_21\"><\/a>\u6837\u4f8b\u8f93\u51fa<\/h5>\n<pre><code>2 4\n<\/code><\/pre>\n<h5><a id=\"_25\"><\/a>\u63d0\u793a<\/h5>\n<p>70%\u6570\u636en<=1000<br \/> 100%\u6570\u636en<=50000<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img-blog.csdnimg.cn\/20200811200031677.jpg?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NjA0ODg0OA==,size_16,color_FFFFFF,t_70\" alt=\"\u56fe\u7247\u53c2\u8003\u4e8e\u6d1b\u8c37\"><\/p>\n<pre><code>#include <bits\/stdc++.h>\nusing namespace std;\nstruct node\n{\n    int to;\n    int next;\n};\nnode e[100500]={0};\nint cnt=0;\nint head[100500]={0};\nint size1[100500]={0};\nint dis[100500]={0};\nint f[100500]={0};\nint n;\nint add(int x,int y)\n{\n    e[++cnt].to=y;\n    e[cnt].next=head[x];\n    head[x]=cnt;\n}\nint dfs1(int now)\n{\n    size1[now]=1;\n    for(int i=head[now];i;i=e[i].next)\n    {\n        int to=e[i].to;\n        if(dis[to])\n            continue;\n        dis[to]=dis[now]+1;\n        dfs1(to);\n        size1[now]+=size1[to];\n    }\n}\nint dfs(int now,int fa)\n{\n    f[now]=f[fa]+n-2*size1[now];\n    for(int i=head[now];i;i=e[i].next)\n    {\n        int to=e[i].to;\n        if(to==fa)\n            continue;\n        dfs(to,now);\n    }\n}\nint main()\n{\n    scanf(\"%d\",&n);\n    for(int i=0;i<n-1;i++)\n    {\n        int a,b;\n        scanf(\"%d%d\",&#038;a,&#038;b);\n        add(a,b);\n        add(b,a);\n    }\n    dis[1]=1;\n    dfs1(1);\n    int maxn=0;\n    for(int i=1;i<=n;i++)\n    {\n        maxn+=dis[i];\n    }\n    maxn-=*n;  \/\/\/\u6bcf\u4e00\u4e2a\u70b9\u52301\u7684\u8ddd\u79bb\u90fd\u662f\u4ece1\u5f00\u59cb\u8ba1\u7b97\uff0c\u987b\u51cf\u53bb\n    f[1]=maxn;\n    for(int i=head[1];i;i=e[i].next)\n    {\n        int to=e[i].to;\n        dfs(to,1);\n    }\n    int ans=0;\n    for(int i=1;i<=n;i++)\n    {\n        if(f[i]<maxn)\n            maxn=f[i],ans=i;\n    }\n    printf(\"%d %dn\",ans,maxn);\n    return 0;\n}\n<\/code><\/pre>\n<p><a href=\"http:\/\/icpc.upc.edu.cn\/problem.php?id=14539\">http:\/\/icpc.upc.edu.cn\/problem.php?id=14539<\/a><\/p>\n<h5><a id=\"_111\"><\/a>\u9898\u76ee<\/h5>\n<p>14539: Ki<\/p>\n<h5><a id=\"_113\"><\/a>\u9898\u76ee\u63cf\u8ff0<\/h5>\n<p>Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1, and the i-th edge (<br \/> 1\u2264i\u2264N\u22121) connects Vertex ai and bi.<br \/> Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0.<br \/> Now, the following Q operations will be performed:<br \/> Operation j (1\u2264j\u2264Q): Increment by xj the counter on every vertex contained in the subtree rooted at Vertex pj.<br \/> Find the value of the counter on each vertex after all operations.<\/p>\n<p>Constraints<br \/> \u00b72\u2264N\u22642\u00d7105<br \/> \u00b71\u2264Q\u22642\u00d7105<br \/> \u00b71\u2264ai<bi\u2264N<br \/> \u00b71\u2264pj\u2264N<br \/> \u00b71\u2264xj\u2264104<br \/> \u00b7The given graph is a tree.<br \/> \u00b7All values in input are integers.<\/p>\n<h5><a id=\"_129\"><\/a>\u8f93\u5165<\/h5>\n<p>Input is given from Standard Input in the following format:<\/p>\n<p>N Q<br \/> a1 b1<br \/> :<br \/> aN\u22121 bN\u22121<br \/> p1 x1<br \/> :<br \/> pQ xQ<\/p>\n<h5><a id=\"_140\"><\/a>\u8f93\u51fa<\/h5>\n<p>Print the values of the counters on Vertex 1,2,\u2026,N after all operations, in this order, with spaces in between.<\/p>\n<h5><a id=\"_143\"><\/a>\u6837\u4f8b\u8f93\u5165<\/h5>\n<p>\u3010\u6837\u4f8b1\u3011<br \/> 4 3<br \/> 1 2<br \/> 2 3<br \/> 2 4<br \/> 2 10<br \/> 1 100<br \/> 3 1<br \/> \u3010\u6837\u4f8b2\u3011<br \/> 6 2<br \/> 1 2<br \/> 1 3<br \/> 2 4<br \/> 3 6<br \/> 2 5<br \/> 1 10<br \/> 1 10<\/p>\n<h5><a id=\"_161\"><\/a>\u6837\u4f8b\u8f93\u51fa<\/h5>\n<p>\u3010\u6837\u4f8b1\u3011<br \/> 100 110 111 110<br \/> \u3010\u6837\u4f8b2\u3011<br \/> 20 20 20 20 20 20<\/p>\n<h5><a id=\"_166\"><\/a>\u63d0\u793a<\/h5>\n<p>\u6837\u4f8b1\u89e3\u91ca<br \/> The tree in this input is as follows:<br \/> <img decoding=\"async\" src=\"https:\/\/imgconvert.csdnimg.cn\/aHR0cDovL2ljcGMudXBjLmVkdS5jbi91cGxvYWQvaW1hZ2UvMjAyMDAyMDQvMjAyMDAyMDQxNjI0NTVfMzc4NzYucG5n?x-oss-process=image\/format,png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><\/p>\n<p>Each operation changes the values of the counters on the vertices as follows:<br \/> \u00b7Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2,3,4. The values of the counters on Vertex 1,2,3,4 are now 0,10,10,10, respectively.<br \/> \u00b7Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1,2,3,4. The values of the counters on Vertex 1,2,3,4 are now 100,110,110,110, respectively.<br \/> \u00b7Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex<br \/> 3, that is, Vertex 3. The values of the counters on Vertex 1,2,3,4 are now 100,110,111,110, respectively.<\/p>\n<p>DFS+\u524d\u7f00\u548c<\/p>\n<pre><code>#include <bits\/stdc++.h>\nusing namespace std;\nstruct node\n{\n    int to;\n    int next;\n};\nnode e[500500]={0};\nint cnt=0;\nint head[500500]={0};\nint dis[500500]={0};\nint n;\nint add(int x,int y)\n{\n    e[++cnt].to=y;\n    e[cnt].next=head[x];\n    head[x]=cnt;\n}\nint dfs(int now,int fa)\n{\n    dis[now]+=dis[fa];\n    for(int i=head[now];i;i=e[i].next)\n    {\n        int to=e[i].to;\n        if(to==fa)\n            continue;\n        dfs(to,now);\n    }\n}\nint main()\n{\n    int q;\n    scanf(\"%d%d\",&n,&q);\n    for(int i=0;i<n-1;i++)\n    {\n        int a,b;\n        scanf(\"%d%d\",&#038;a,&#038;b);\n        add(a,b);\n        add(b,a);\n    }\n    for(int i=1;i<=q;i++)\n    {\n        int x,y;\n        scanf(\"%d%d\",&#038;x,&#038;y);\n        dis[x]+=y;\n    }\n    for(int i=head[1];i;i=e[i].next)\n    {\n        int to=e[i].to;\n        dfs(to,1);\n    }\n    for(int i=1;i<=n;i++)\n    {\n        printf(\"%d \",dis[i]);\n    }\n    return 0;\n}\n<\/code><\/pre>\n<p><a href=\"http:\/\/icpc.upc.edu.cn\/problem.php?id=15047\">http:\/\/icpc.upc.edu.cn\/problem.php?id=15047<\/a><\/p>\n<h5><a id=\"_239\"><\/a>\u9898\u76ee<\/h5>\n<p>15047: \u80d6\u864e\u7684\u83dc\u54c1<\/p>\n<h5><a id=\"_241\"><\/a>\u9898\u76ee\u63cf\u8ff0<\/h5>\n<p>\u80d6\u864e\u60ca\u559c\u5730\u53d1\u73b0\u4e86\u6709N\u4e2a\u7a97\u53e3\u6709\u4ed6\u6700\u559c\u6b22\u5403\u7684\u83dc\uff08\u5176\u5b9e\u90fd\u559c\u6b22\uff1f\uff09\uff0c\u4f46\u662f\u4ed6\u60f3\u5728\u79fb\u52a8\u6700\u77ed\u8ddd\u79bb\uff08\u6bd5\u7adf\u8d70\u591a\u4e86\u4e5f\u662f\u4f1a\u7d2f\u7684\uff09\u7684\u60c5\u51b5\u4e0b\u5403\u5230\u6240\u6709\u4ed6\u559c\u6b22\u5403\u7684\u83dc\u54c1\uff0c\u9965\u997f\u7684\u4ed6\u5df2\u7ecf\u6ca1\u6709\u529b\u6c14\u5199\u51fa\u4ee3\u7801\u6765\u8ba1\u7b97\u81ea\u5df1\u7684\u6700\u4f73\u65b9\u6cd5\u4e86\uff0c\u6240\u4ee5\u4ed6\u627e\u5230\u4e86\u4f60\uff0c\u6765\u5e2e\u4ed6\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002\u73b0\u5728\u7ed9\u4f60N\u4e2a\u7a97\u53e3\u53ca\u7a97\u53e3\u7684\u5750\u6807\uff0c\u8bf7\u8f93\u51fa\u80d6\u864e\u6240\u8981\u79fb\u52a8\u7684\u6700\u5c0f\u8ddd\u79bb\u603b\u548c\u3002<br \/> \u80d6\u864e\u4e00\u5f00\u59cb\u5728(0,0)\u70b9\u5904\u3002<\/p>\n<h5><a id=\"_245\"><\/a>\u8f93\u5165<\/h5>\n<p>\u7b2c\u4e00\u884c\u4e00\u4e2a\u6b63\u6574\u6570n\uff081\u2264n\u226413\uff09 \u3002<br \/> \u63a5\u4e0b\u6765\u6bcf\u884c2\u4e2a\u5b9e\u6570\uff0c\u8868\u793a\u7b2ci\u5757\u7a97\u53e3\u7684\u5750\u6807\u3002<br \/> \u4e24\u70b9\u4e4b\u95f4\u7684\u8ddd\u79bb\u516c\u5f0f\u4e3a<\/p>\n<h5><a id=\"_249\"><\/a>\u8f93\u51fa<\/h5>\n<p>\u4e00\u4e2a\u6570\uff0c\u8868\u793a\u8981\u8dd1\u7684\u6700\u5c11\u8ddd\u79bb\uff0c\u4fdd\u75592\u4f4d\u5c0f\u6570\u3002<\/p>\n<h5><a id=\"_251\"><\/a>\u6837\u4f8b\u8f93\u5165<\/h5>\n<pre><code>4\n1 1\n1 -1\n-1 1\n-1 -1\n<\/code><\/pre>\n<h5><a id=\"_259\"><\/a>\u6837\u4f8b\u8f93\u51fa<\/h5>\n<pre><code>7.41\n<\/code><\/pre>\n<p>\u72b6\u538bDP<\/p>\n<pre><code>#include <bits\/stdc++.h>\n#define inf 0x3f3f3f3f\nusing namespace std;\ndouble dp[1<<14][20]={0};\nstruct node\n{\n    double x;\n    double y;\n};\nnode a[20]={0};\ndouble q(int i,int j)\n{\n    double sum=sqrt((double)((a[i].x-a[j].x)*(a[i].x-a[j].x)*1.0+(a[i].y-a[j].y)*(a[i].y-a[j].y)*1.0));\n    return sum;\n}\nint main()\n{\n    int n;\n    scanf(\"%d\",&#038;n);\n    for(int i=1;i<=n;i++)\n    {\n        scanf(\"%lf%lf\",&#038;a[i].x,&#038;a[i].y);\n    }\n    for(int i=0;i<(1<<(n+1));i++)\n    {\n        for(int j=0;j<=n;j++)\n        {\n            dp[i][j]=999999999;\n        }\n    }\n    dp[1][0]=0;\n    for(int i=0;i<(1<<(n+1));i+=1)\n    {\n        for(int j=0;j<=n;j++)\n        {\n            if(!(i>>j)&1)\n                continue;\n            for(int k=0;k<=n;k++)\n            {\n                if(j==k)\n                    continue;\n                if(!(i>>k)&1)\n                    continue;\n                dp[i][j]=min(dp[i][j],dp[i^(1<<j)][k]+q(k,j));\n            }\n        }\n    }\n    double min1=99999999;\n    int k=(1<<(n+1))-1;\n    for(int i=1;i<=n;i++)\n    {\n        min1=min(min1,dp[k][i]);\n    }\n    printf(\"%.2fn\",min1);\n    return 0;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/icpc.upc.edu.cn\/pr&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-33","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/wordpress.tim-wcx.ltd\/index.php\/wp-json\/wp\/v2\/posts\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.tim-wcx.ltd\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.tim-wcx.ltd\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.tim-wcx.ltd\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.tim-wcx.ltd\/index.php\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.tim-wcx.ltd\/index.php\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.tim-wcx.ltd\/index.php\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.tim-wcx.ltd\/index.php\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.tim-wcx.ltd\/index.php\/wp-json\/wp\/v2\/tags?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}