博客
关于我
【ybtoj】【并查集】【例题1】【模板】并查集
阅读量:328 次
发布时间:2019-03-04

本文共 546 字,大约阅读时间需要 1 分钟。

【例题1】【模板】并查集


Link


解题思路

真真就是个并查集模板


Code

#include 
#include
using namespace std;int n, m, fa[10010], c, x, y, xx, yy;int find(int x) { if(fa[x] != x) { fa[x] = find(fa[x]); return fa[x]; } return x;}int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) fa[i] = i; for (int i = 1; i <= m; i++) { scanf("%d %d %d", &c, &x, &y); if(c == 1) { xx = find(x), yy = find(y); if(xx != yy) fa[xx] = yy; } else { xx = find(x), yy = find(y); if(xx != yy) printf("N\n"); else printf("Y\n"); } }}

转载地址:http://gyiq.baihongyu.com/

你可能感兴趣的文章
MySQL锁
查看>>
MySQL锁与脏读、不可重复读、幻读详解
查看>>
MySQL锁机制
查看>>
mysql锁机制,主从复制
查看>>
Mysql锁机制,行锁表锁
查看>>
MySQL锁表问题排查
查看>>
Mysql锁(2):表级锁
查看>>
MySQL锁,锁的到底是什么?
查看>>
MySQL错误-this is incompatible with sql_mode=only_full_group_by完美解决方案
查看>>
Mysql错误2003 -Can't connect toMySQL server on 'localhost'(10061)解决办法
查看>>
MySQL错误提示mysql Statement violates GTID consistency
查看>>
mysql错误:This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de
查看>>
mysql长事务
查看>>
mysql问题记录
查看>>
mysql间隙锁
查看>>
MySQL集群解决方案(1):MySQL数据库的集群方案
查看>>
MySQL集群解决方案(2):主从复制架构
查看>>
MySQL集群解决方案(4):负载均衡
查看>>
MySQL集群解决方案(5):PXC集群
查看>>
MySQL面试宝典
查看>>