随笔分类 - 并查集
摘要:http://poj.org/problem?id=2513题意:有一些棒子,每一根的两头都有两个颜色,将这些棒子相连并且被两根棒子接头处是相同的颜色,求一些这样的棒子是否都可以全部连起来;思路:首先用tree树给每一种颜色编号,然后用并查集+欧拉路(只有两个或零个奇数结点);代码:View Code #include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>using namespace std;int f[500010] = {0};int n = 0;in
阅读全文
摘要:一道简单的并查集题目,刚开始还以为是搜索的题目,又加上读错了题目,纠结了一天,直到看了E_star的解题报告;思路:先按速从小到大排序,然后两个for循环,如果从第 i 条路到第 j 条路之间的所有路能够让 i 和 j 连通,那么,这就存在一条路,且这条路的舒适度就是 两者的差值。http://acm.hdu.edu.cn/showproblem.php?pid=1598View Code 1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<cstring&g
阅读全文

浙公网安备 33010602011771号