# [BZOJ1050][HAOI2006]旅行comf

## 1050: [HAOI2006]旅行comf

Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 3450  Solved: 1919 [Submit][Status][Discuss]

## Input

，车辆必须以速度v在该公路上行驶。最后一行包含两个正整数s，t，表示想知道从景点s到景点t最大最小速度比

1<N<=500,1<=x,y<=N，0<v<30000，0<M<=5000

【样例输入1】
4 2
1 2 1
3 4 2
1 4
【样例输入2】
3 3
1 2 10
1 2 5
2 3 8
1 3
【样例输入3】
3 2
1 2 2
2 3 4
1 3

## Sample Output

【样例输出1】
IMPOSSIBLE
【样例输出2】
5/4
【样例输出3】
2

#include <cstdio>
#include <algorithm>
using namespace std;
int n = 0;
char ch = getchar();
while(ch < '0' || ch > '9') ch = getchar();
while(ch <= '9' && ch >= '0'){
n = (n << 1) + (n << 3) + ch - '0';
ch = getchar();
}
return n;
}
const int maxn = 500 + 10, maxm = 5000 + 10;
struct Edge{
int u, v, w;
Edge(){}
bool operator < (const Edge &x) const {
return w < x.w;
}
}e[maxm];
int fa[maxn];
int Find(int x){
return x == fa[x] ? x : fa[x] = Find(fa[x]);
}
int Gcd(int a, int b){
int t;
if(a > b){
t = a;
a = b;
b = t;
}
while(a){
t = a;
a = b % a;
b = t;
}
return b;
}
int main(){
int n, m;
for(int i = 1; i <= m; i++){
}
sort(e + 1, e + m + 1);
int s, t, ans1 = 30000, ans2 = 0;
for(int st = 1; st <= m; st++){
for(int i = 1; i <= n; i++) fa[i] = i;
for(int i = st; i <= m; i++){
fa[Find(e[i].u)] = Find(e[i].v);
if(Find(s) == Find(t)){
if(ans1 * e[st].w > ans2 * e[i].w){
ans1 = e[i].w;
ans2 = e[st].w;
}
break;
}
}
}
if(ans2 == 0) puts("IMPOSSIBLE");
else{
int t = Gcd(ans1, ans2);
if(ans2 != t) printf("%d/%d\n", ans1 / t, ans2 / t);
else printf("%d\n", ans1 / t);
}
return 0;
}

posted @ 2017-08-29 20:29  Elder_Giang  阅读(42)  评论(0编辑  收藏