# BZOJ1050 旅行comf

### ｃｏｄｅ

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
#define PAUSE printf("Press Enter key to continue..."); fgetc(stdin);
const int M=5005;
const int N=505;
int n,m,s,t;
int ansA,ansB;
struct edge {
int f,t,w;
bool operator < (const edge &rhs) const {
return w<rhs.w;
}
}E[M];
int fa[N];
/*==================Define Area================*/
void init() {
for(int i=1;i<=n;i++) fa[i]=i;
}

int find(int x) {
return fa[x]==x?x:fa[x]=find(fa[x]);
}

void unite(int x,int y) {
x=find(x);y=find(y);
if(x==y) return ;
fa[x]=y;
return ;
}

int Gcd(int x,int y) {
if(!y) return x;
else return Gcd(y,x%y);
}

int main() {
for(int i=1;i<=m;i++) {
}
sort(E+1,E+1+m);
for(int i=1;i<=m;i++) {
init();
int tmp=i;
while(tmp<=m&&find(s)!=find(t)) {
unite(E[tmp].f,E[tmp].t);
tmp++;
}
tmp--;
if(find(s)!=find(t)) continue ;
if(!ansA||E[tmp].w*1.0/E[i].w<ansA*1.0/ansB) {
ansA=E[tmp].w;
ansB=E[i].w;
}
}
if(!ansA) return puts("IMPOSSIBLE"),0;
if(!(ansA%ansB)) printf("%d\n",ansA/ansB);
else {
int G=Gcd(ansA,ansB);
printf("%d/%d\n",ansA/G,ansB/G);
}
return 0;
}
posted @ 2018-08-06 21:13  Apocrypha  阅读(77)  评论(0编辑  收藏