UVALive 5865 Finding Bottleneck Shorstet Paths
来源:互联网 发布:平安证券软件官网 编辑:程序博客网 时间:2024/05/16 18:48
题目链接:http://livearchive.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3876
不知道比赛的时候是怎么想的,居然没有想到并查集,肯定是太久没做,失去对并查集的敏感度了。。。。
数据范围比较小,所有的边也只有100W而已,明显可以过的。
感觉就是最小生成树的思想,或者是一部分的最小生成树
简单并查集
#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<queue>using namespace std;const int maxn=1111;int x[maxn],y[maxn];struct in{int u,v,w;}edge[maxn*maxn];int belg[maxn];int findx(int x){return x==belg[x]?x:findx(belg[x]);}void Union(int a,int b){int ra=findx(a),rb=findx(b);belg[ra]=rb;}bool cmp(in x,in y){return x.w<y.w;}int main(){int n;while(scanf("%d",&n)!=EOF){if(n==0)break;for(int i=0;i<n;i++)scanf("%d%d",&x[i],&y[i]);int tot=0;for(int i=0;i<n;i++){belg[i]=i;for(int j=i+1;j<n;j++){edge[tot].u=i;edge[tot].v=j;edge[tot++].w=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);}}int s,e;scanf("%d%d",&s,&e);s-=1;e-=1;sort(edge,edge+tot,cmp);int ans;for(int i=0;i<n*n;i++){if(findx(edge[i].u)!=findx(edge[i].v))Union(edge[i].u,edge[i].v);if(findx(s)==findx(e)){ans=edge[i].w;break;}}if(s==e)ans=0;printf("%d\n",ans);}return 0;}
- UVALive 5865 Finding Bottleneck Shorstet Paths
- UVAlive 5867 Finding Feasible Paths 题解
- UVALive 6955Finding Lines
- UVALive 6955Finding Lines
- UVALive 6955Finding Lines
- [水]20121004Finding Feasible Paths
- uvalive 6955 Finding Lines rand()应用
- [UVALive 6955 Finding Lines]概率+随机算法
- uvalive 6955 Finding Lines rand() 随机算法
- UVALive 7744 Finding Hotels(kd tree)
- UVALive 6955 Finding Lines(奇特的过题方式)
- Finding Lines UVALive 6955(rand随机化过题 )
- Finding all paths climbing stairs in one or two steps.
- Finding all possible simple paths (paths without cycles) between two vertices in a graph
- Uvalive 4267 Finding The Heaviest Path (Regionals 2008 Asia Taipei +DFS结点最大权值路径)
- 职业瓶颈 career bottleneck
- Performance bottleneck thresholds
- UVALive
- 菜鸟学 C#调用存储过程操作oracle数据库中的表
- Start AdminServer And NodeManager Using WLST
- DOM标准
- hibernate复习的笔记
- fortran学习
- UVALive 5865 Finding Bottleneck Shorstet Paths
- Linux命令整理之三:ln
- 等等
- SQL相除
- Linux下通用线程池的构建
- Flex使用Popupmanager弹出窗口的交互传值方法
- typedef和typename关键字
- tomcat类加载器测试
- 部署错误:尚未授予访问 Tomcat 服务器的权限。请在服务器管理器的 Tomcat 定制器中设置 "manager-script" 角色的正确用户名和口令。 有关详细信息,请查看服务器日志。