【解题思路】

  先把边按边权排序,然后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. websocket 中使用Service层的方法

    创建公共Utils 类 ApplicationContextRegister @Component @Lazy(false) public class ApplicationContextRegist ...

  2. POJ 2299 Ultra-QuickSort (树状数组+离散化 求逆序数)

    In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a seque ...

  3. Cisco基础(六):配置目前网络环境、项目阶段练习

    一.配置目前网络环境 目标: 一家新创建的IT公司,公司位于北京有80多台服务器 目前网络环境使用技术,通过端口映射技术将web服务器发布给Internet: 三层交换:汇聚接入层交换机 默认路由:实 ...

  4. Mysql忘记密码:关于ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)的问题

    命令行登录mysql时,出现ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)的提示. ...

  5. [CSP-S模拟测试]:玄学题/c(数学)

    题目传送门(内部题40) 输入格式 第一行:两个正整数$n$.$m$. 输出格式 第一行:一个整数,代表式子的值. 样例 样例输入1: 4 5 样例输出1: 0样例输入2: 799 8278 样例输出 ...

  6. CenterOS 设置静态IP

    本文主要介绍这样再CenterOS 中设定静态IP. 工具 centerOS 6.9 步骤 执行命令:vi /etc/sysconfig/network-scripts/ifcfg-eth0 编辑,填 ...

  7. idea 查看字节码 bytecode插件 (jclasslib Bytecode Viewer、ASM Bytecode Viewer )

    文章目录 jclasslib Bytecode Viewer ASM Bytecode Viewer jclasslib Bytecode Viewer 然后重启idea===>重新编译(构建项 ...

  8. 1. 什么是Prometheus

    什么是Prometheus Prometheus是一个最初在SoundCloud上构建的开源系统监视和警报工具包 .自2012年成立以来,许多公司和组织都采用了Prometheus,该项目拥有一个非常 ...

  9. #include和前置声明(forward declaration)

    #include和前置声明(forward declaration) 1.    当不需要调用类的实现时,包括constructor,copy constructor,assignment opera ...

  10. PAT_A1131#Subway Map

    Source: PAT A1131 Subway Map (30 分) Description: In the big cities, the subway systems always look s ...