版本比较
4.26 最小生成树进阶 总结
正文
增加 8 行删除 8 行
41 行未改动4243444546464748495028 行未改动7980818283838485868739 行未改动12712812913013113113213313413549 行未改动18518618718818918919019119219314 行未改动2082092102112122122132142152163 行未改动22022122222322422422522622722845 行未改动27427527627727827827928028128238 行未改动32132232332432532532632741 行未改动void unite(int x,int y){ int rootx=find(x); int rooty=find(y); if(rootx!=rooty)pre[rootx]=rooty; return ; return ;}//----------------------并查集模版-------------------bool cmp(Edge A,Edge B){ return A.w<B.w;28 行未改动 int T=1; //cin>>T; while(T--)solve(); return 0;} }```## P1194 买礼物此题我的思路有些不同
39 行未改动void unite(int x,int y){ int rootx=find(x); int rooty=find(y); if(rootx!=rooty)pre[rootx]=rooty; return ; return ;}//----------------------并查集模版-------------------void add_edge(int u,int v,int w){ e[++idx]={u,v,w};49 行未改动 int T=1; //cin>>T; while(T--)solve(); return 0;} }```## P2916 [USACO08NOV Cheering up the Cow G这题我们就需要手推样例了
14 行未改动$c_4 + l_7 + c_5 + l_7 + c_4 + l_3 + c_2 + l_2 + c_3 + l_2 + c_2 + l_1 + c_1 + l_1 + c_2 + l_3 + c_4$
可以简化成:
$c_4 + 2 \times l_7 + c_5 + 2 \times c_4 + 2 \times l_3 + 3 \times c_2 + 2 \times l_2 + c_3 + 2 \times l_1 + c_1$ $c_4 + 2 \times l_7 + c_5 + 2 \times c_4 + 2 \times l_3 + 3 \times c_2 + 2 \times l_2 + c_3 + 2 \times l_1 + c_1$
上面加起来就是 176
我们如果第二步不去 5 而去 2 呢(但是经过的边不变)3 行未改动$c_4 + l_3 + c_2 + l_1 + c_1 + l_1 + c_2 + l_2 + c_3 + l_2 + c_2 + l_3 + c_4 + l_7 + c_5 + l_7 + c_4$
可以简化成:
$c_4 + 2 \times l_7 + c_5 + 2 \times c_4 + 2 \times l_3 + 3 \times c_2 + 2 \times l_2 + c_3 + 2 \times l_1 + c_1$ $c_4 + 2 \times l_7 + c_5 + 2 \times c_4 + 2 \times l_3 + 3 \times c_2 + 2 \times l_2 + c_3 + 2 \times l_1 + c_1$
和第一个路径一模一样
我们把初始节点换成 5 经过边不变,再跑一次45 行未改动void unite(int x,int y){ int rootx=find(x); int rooty=find(y); if(rootx!=rooty)pre[rootx]=rooty; return ; return ;}bool cmp(Edge A,Edge B){ return A.w<B.w;}38 行未改动 int T=1; //cin>>T; while(T--)solve(); return 0;} }```##