【解题思路】

  先把边按边权排序,然后O(m)暴力枚举最小边,对于每条最小边,将比其大的边按序加入直到起终点连通,此时最大边权/最小边权即为选择该最小边情况下的最小比值。复杂度O(m(m+n)α(n))。

【参考代码】

 #include <bits/stdc++.h>
#define range(i,c,o) for(register int i=(c);i<(o);++i)
#define dange(i,c,o) for(register int i=(c);i>(o);--i) //#define __debug
#ifdef __debug
#define Function(type) type
#define Procedure void
#else
#define Function(type) __attribute__((optimize("-O2"))) inline type
#define Procedure __attribute__((optimize("-O2"))) inline void
#endif #ifdef __int128_t
typedef __int128_t integer;
#else
typedef long long integer;
#endif using namespace std; //quick_io {
Function(integer) getint()
{
char c=getchar(); for(;!isdigit(c)&&c!='-';c=getchar());
short s=; for(;c=='-';c=getchar()) s*=-; integer r=;
for(;isdigit(c);c=getchar()) (r*=)+=c-''; return s*r;
}
//} quick_io struct edge
{
int fr,to,vl;
edge(const int&f=,const int&t=,const int&v=):
fr(f),to(t),vl(v) {}
Procedure input() {fr=getint(),to=getint(),vl=getint();}
Function(bool) operator<(const edge&t)const
{
return vl<t.vl;
}
}edg[]; int fat[];
int getfa(const int&x) {return fat[x]==x?x:fat[x]=getfa(fat[x]);} int main()
{
int n=getint(),m=getint(); range(i,,m) edg[i].input();
int S=getint(),T=getint(),up=,down=; sort(edg,edg+m);
range(i,,m)
{
range(j,,n+) fat[j]=j;
range(j,i,m)
{
fat[getfa(edg[j].fr)]=getfa(edg[j].to);
if(getfa(S)==getfa(T))
{
if(!up||up*edg[i].vl>down*edg[j].vl)
{
up=edg[j].vl,down=edg[i].vl;
}
break;
}
}
}
if(!up) return puts("IMPOSSIBLE"),;
int g=__gcd(up,down); up/=g,down/=g;
return down==?printf("%d\n",up):printf("%d/%d\n",up,down),;
}

bzoj1050题解的更多相关文章

  1. 【BZOJ1050】[HAOI2006]旅行

    [BZOJ1050][HAOI2006]旅行 题面 bzoj 洛谷 题解 先将所有边从小往大排序 枚举钦定一条最小边 再枚举依次枚举最大边,如果两个点联通了就\(break\)统计答案即可 代码 #i ...

  2. 【BZOJ1050】[HAOI2006]旅行comf 并查集

    [BZOJ1050][HAOI2006]旅行comf Description 给你一个无向图,N(N<=500)个顶点, M(M<=5000)条边,每条边有一个权值Vi(Vi<300 ...

  3. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  4. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  5. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  6. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  7. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  8. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  9. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

随机推荐

  1. 关于scrub的详细分析和建议

    https://ceph.com/planet/%E5%85%B3%E4%BA%8Escrub%E7%9A%84%E8%AF%A6%E7%BB%86%E5%88%86%E6%9E%90%E5%92%8 ...

  2. C# GDI+简单绘图

    一.使用Pen画笔 Pen的主要属性有: Color(颜色),DashCap(短划线终点形状),DashStyle(虚线样式),EndCap(线尾形状), StartCap(线头形状),Width(粗 ...

  3. Python每日一题 008

    题目 基于多线程的网络爬虫项目,爬取该站点http://www.tvtv.hk 的电视剧收视率排行榜 分析 robots.txt User-agent: Yisouspider Disallow: / ...

  4. 2019 牛客暑期多校 第一场 H XOR (线性基)

    题目:https://ac.nowcoder.com/acm/contest/881/H 题意:求一个集合内所有子集异或和为0的长度之和 思路:首先集合内异或和,这是线性基的一个明显标志,然后我们不管 ...

  5. python 去除字符串两端字符串

    转载:http://blog.sina.com.cn/s/blog_940224600100w8l0.html Python中的strip用于去除字符串的首位字符,同理,lstrip用于去除左边的字符 ...

  6. 9、继续matlab数值分析

    1.matlab拉格朗日插值 function yi=Lagrange(x,y,xi) %x为向量,全部的插值节点 %y为向量,插值节点处的函数值 %xi为标量或向量,被估计函数的自变量: %yi为x ...

  7. mysql存储过程、函数、触发器、

    当数据库版本不允许直接使用存储过程.函数的语法时用delimiter // 将结束符改成//用完之后再写delimiter;将结束符改回来即可,调用过程.函数用call+其名字即可返回结果 delim ...

  8. 28. Python编写自动化测试用例

    接口文档已经提供了,requests库.unittest单元测试框架也已经介绍过,笔者相信读者朋友已经可以独立编写接口自动化测试用例了.但是有一些细节,我们需要聊一下.比如我们写登录接口测试用例,用户 ...

  9. HDU 3746 Cyclic Nacklace (KMP找循环节)

    题目链接:HDU 3746 Sample Input 3 aaa abca abcde Sample Output 0 2 5 Author possessor WC Source HDU 3rd & ...

  10. gitlab搭建使用

    1.安装gitlab __环境准备__ [root@gitlab ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [r ...