随笔分类 -  并查集

摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2497题意 : 给定一个 无向图 和 一个点 s 求 是否 图中的 所有环 都包含 点s (保证 图中 至少 有 一个环)题解 : dfs 求解 只要 搜到 一个 被访问过的点 而且这个点 不是 s 那么 就有环 不含有 sView Code 1#include<cstdio>2#include<cstring>3#include<cmath>4#include<iostream>5#includ 阅读全文
posted @ 2012-12-02 19:32 Szz 阅读(209) 评论(0) 推荐(0)
摘要:1 递归形式 2 3 int find(int x) 4 { 5 if(x!=f[x])f[x]=find(f[x]); 6 return f[x]; 7 } 8 9 10 非递归11 int find(int x)12 {13 if(f[x]==x)return x;14 int r=x;15 while(r!=f[r])16 {17 r=f[r];18 }19 int y=x,k;20 while(y!=f[y])21 {22 23 k=f[y];24 f[y... 阅读全文
posted @ 2012-03-15 21:08 Szz 阅读(199) 评论(0) 推荐(0)