
并查集
苍山洱海胖
慢一点 不要悬浮
展开
-
【hdu 1232】 畅通工程
畅通工程 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。问最少还需要建设多少条道路? Input测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是城镇数目N ( 注意:两个城市之间可以有多条道路相原创 2017-08-03 10:39:37 · 299 阅读 · 0 评论 -
【并查集&路径压缩 模板】
void init(int n) //将所有子节点的父节点初始化成自己本身{ for (int i = 0; i <= n; i++) par[i] = i;}//压缩和不压缩的都要知道,后边有时会处理不压缩的; int find(int x) //找一个点的根结点 {1. if ( x!= par[x]) return /* */find(pa原创 2017-08-13 13:31:52 · 387 阅读 · 0 评论 -
【hdu 1213】How Many Tables
How Many Tables Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the fr原创 2017-08-03 10:44:08 · 311 阅读 · 0 评论