博客
关于我
Lougu P2502 & SSL1312 A-B 数对【并查集】
阅读量:339 次
发布时间:2019-03-04

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

在这里插入图片描述

今天复习了并查集!


首先对输入的速度 v v v进行结构体排序

不断地合并路径直到起点与终点相连
算出最大最小速度比并不断更新最小。
最后分三种情况输出。

具体看:

代码

#include
#include
#include
#include
using namespace std;int h[100010],fa[100010];double minn=2147483647;int n,m,s,t,ss,tt;int tot;struct node{ int x,y,v;}a[1000010];bool cmp(const node&a,const node&b){ return a.v
>n>>m; for(int i=1; i<=m; i++) scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].v); cin>>s>>t; sort(a+1,a+1+m,cmp); for(int i=1; i<=m; i++) { for(int j=1; j<=n; j++) fa[j]=j; int k=i,w=0; while(k<=m) { fa[find(a[k].x)]=find(a[k].y); //合并 if(find(s)==find(t)) //判断起终点是否属于同一个集合 { w=1; break; } k++; } if(w==1) { if(a[k].v*1.0/a[i].v*1.0

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

你可能感兴趣的文章
mysql 5.6 修改端口_mysql5.6.24怎么修改端口号
查看>>
MySQL 8.0 恢复孤立文件每表ibd文件
查看>>
MySQL 8.0开始Group by不再排序
查看>>
mysql ansi nulls_SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON 什么意思
查看>>
multi swiper bug solution
查看>>
MySQL Binlog 日志监听与 Spring 集成实战
查看>>
MySQL binlog三种模式
查看>>
multi-angle cosine and sines
查看>>
Mysql Can't connect to MySQL server
查看>>
mysql case when 乱码_Mysql CASE WHEN 用法
查看>>
Multicast1
查看>>
mysql client library_MySQL数据库之zabbix3.x安装出现“configure: error: Not found mysqlclient library”的解决办法...
查看>>
MySQL Cluster 7.0.36 发布
查看>>
Multimodal Unsupervised Image-to-Image Translation多通道无监督图像翻译
查看>>
MySQL Cluster与MGR集群实战
查看>>
multipart/form-data与application/octet-stream的区别、application/x-www-form-urlencoded
查看>>
mysql cmake 报错,MySQL云服务器应用及cmake报错解决办法
查看>>
Multiple websites on single instance of IIS
查看>>
mysql CONCAT()函数拼接有NULL
查看>>
multiprocessing.Manager 嵌套共享对象不适用于队列
查看>>