并查集
来源:互联网 发布:影响原油数据 编辑:程序博客网 时间:2024/05/29 16:43
2015 netease autunm campus recruitment
union_find
#encoding=utf8def find_father(s): if s in root_num: return s if s in father_dict: return find_father(father_dict[s]) return NoneN = int(raw_input())f = []while N: N-=1 f.append(raw_input().split(' '))root_num = {}father_dict = {}for i in f: a = i[0] b = i[1] af = find_father(a) bf = find_father(b) if not af and not bf: father_dict[a] = a father_dict[b] = a if a != b: root_num[a] = 2 else: root_num[a] = 1 elif None in (af,bf): if af is None: father = bf nof = a else: father = af nof = b father_dict[nof] = father root_num[father] += 1 elif af != bf: ra = root_num[af] rb = root_num[bf] if ra > rb: br = af sr = bf else: br = bf sr = af root_num[br] += root_num[sr] father_dict[sr] = br root_num.pop(sr)data = sorted(root_num.values(),reverse=True)for i in data:print i
0 0
- HDU3938 并查集 并查集
- 并查集(集并查)
- HDU1232 并查集<并>
- 并查集
- 数据结构-并查集
- 并查集
- 并查集!
- 并查集
- 并查集
- 并查集
- 并查集
- 并查集总结
- 并查集学习
- 并查集
- 并查集
- 并查集
- 所谓并查集
- 并查集
- FileFilter和FilenameFilter的区别
- Changed limits: max_open_files: 2048 max_connections: 2038 table_cache: 64
- ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
- 判断二叉树是否对称
- 递归复制文件夹
- 并查集
- linq 动态排序 order by
- 伪冒泡排序------数组/链表实现
- 索引扫描
- HDU 1796 How many integers can you find
- 【SpringMVC整合MyBatis】提供学习参考的项目源码
- 欢迎使用CSDN-markdown编辑器
- 常用容器
- ArrayList类的toArray方法