【解题思路】

  先把边按边权排序,然后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. 【leetcode】987. Vertical Order Traversal of a Binary Tree

    题目如下: Given a binary tree, return the vertical order traversal of its nodes values. For each node at ...

  2. parse_str()函数怎么用?

    php parse_str()函数 语法 parse_str()函数怎么用? php parse_str()函数表示将字符串解析成多个变量,语法是parse_str(string,array),如果未 ...

  3. 【Flutter学习】事件处理与通知之事件处理

    一,概述 移动应用中一个必不可少的环节就是与用户的交互,在Flutter中提供的手势检测为GestureDetector. Flutter中的手势系统分为二层: 第一层是触摸原事件(指针) Point ...

  4. Python基础教程(007)--Python的优缺点

    前言 了解Python的优点和缺点 知识点 优点 简单易学 免费,开源 面相对象 丰富的库 可扩展性 缺点 运行速度慢 国内市场较小 中文资料匮乏 总结: 明白Python的优点和缺点

  5. CF 1150 D Three Religions——序列自动机优化DP

    题目:http://codeforces.com/contest/1150/problem/D 老是想着枚举当前在给定字符串的哪个位置,以此来转移. 所以想对三个串分别建 trie 树,然后求出三个t ...

  6. jekins—持续集成

    json转换为Python的字典形式 Martin fowler:通过自动化的构建,编译-发布-自动化测试,尽早的发现集成的错误 持续集成的要素: 统一的代码库 自动构建编译 自动测试(单元测试) 每 ...

  7. Another Blog

    I also hold a blog with thoughts of English learning. Get there ===>. It's a private blog. Actual ...

  8. 【从0到1,搭建Spring Boot+RESTful API+Shiro+Mybatis+SQLServer权限系统】05、Shiro集成

    1.POM文件中加入Shiro和fastJSON依赖 <dependency> <groupId>org.apache.shiro</groupId> <ar ...

  9. error C4996: 'stricmp': The POSIX name for this item is deprecated

    转自VC错误:http://www.vcerror.com/?p=164 问题描述: 最近使用了VS2012,在使用 stricmp和ltoa函数的时候,报出了以下错误信息 error C4996: ...

  10. msfpayload的用法

    daniel@daniel-mint ~/msf/metasploit-framework $ ruby msfpayload windows/exec CMD=calc.exe C WARNING: ...