博客
关于我
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/

你可能感兴趣的文章
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>