对并查集的路径压缩有了新的认识
添加链接描述
int unionsearch(int root)
{
int son, tmp;
son = root;
while(root != pre[root]) //寻找掌门ing……
root = pre[root];
while(son != root) //路径压缩
{
tmp = pre[son];
pre[son] = root;
son = tmp;
}
return root; //掌门驾到~
}
哈尔滨工业大学 (威海)
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int SIZE = 20;
ll L[SIZE] = {
0, 9};
ll B[SIZE] = {
0, 1};
int cnt;
inline void build()
{
cnt = 2;
for (; cnt < 20; cnt++)
{
B[cnt] = B[cnt - 1] * 10LL;
L[cnt]