博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LA3027(并查集)
阅读量:6934 次
发布时间:2019-06-27

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

题目大意很简单,按照命令连接节点,findset函数写的时候费了点劲儿,要注意那个累加距离值。

其实因为刚开始学,还是对并查集的查询和连接不是很熟悉,多推几次就好了。

1 #include
2 #include
3 #include
4 using namespace std; 5 int set[20010],p[20010]; 6 int findset(int x) 7 { 8 int ans; 9 if(set[x]==x)10 return x;11 else12 {13 ans=findset(set[x]);14 p[x]+=p[set[x]];15 return set[x]=ans;16 }17 }18 int main()19 {20 int T,i;21 scanf("%d",&T);22 while(T--)23 {24 int n,u,v;25 scanf("%d",&n);26 for(int i=0;i

 

 

转载于:https://www.cnblogs.com/Acgsws/p/3221613.html

你可能感兴趣的文章
在一个页面加载另一个渲染的页面
查看>>
linux 历史(histroy)命令记录过滤
查看>>
APACHE 安装出错 configure: error: Cannot use an external APR with the bundled APR-util
查看>>
PHP性能调优,PHP慢日志---PHP脚本执行效率性能检测之WebGrind的使用
查看>>
linux工具之curl与wget高级使用
查看>>
FFmpeg Installation for Ubuntu
查看>>
mysql中表名不区分大小写
查看>>
理解Docker——深入引擎室
查看>>
讨论Linux目录结构
查看>>
LINUX开启SNMP方法
查看>>
shell-变量的数值计算
查看>>
php-fpm的pool、php-fpm慢执行日志、open_basedir、php-fpm进程管理
查看>>
centos6.8安装 gitlab 9.3.5及使用
查看>>
字符转换指令tr,col,expand
查看>>
Egret之位图字体
查看>>
python安装MySQLdb出错解决方案
查看>>
Unable to find remote helper for 'https'解决办法
查看>>
kvm使用详解
查看>>
javascript的正则表达式
查看>>
zabbix3.2.6.1升级3.4.4图文心得
查看>>