未完

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#define eps 1e-7
using namespace std;
const int maxn=100002;
struct data{int x,y; double val,val1,val2; };
data e[maxn],e1[maxn];
int n,m,f[maxn];
bool cmp(data a,data b){ return (a.val<b.val);}
void init(){
scanf("%d%d",&n,&m);
for (int i=1;i<=m;i++){ scanf("%d%d%d%d",&e[i].x,&e[i].y,&e[i].val1,&e[i].val2);}
}


void make_set(){ for (int i=1;i<=m;i++) f[i]=i;}
void unionn(int a,int b){ f[a]=b;}
int find(int x){ if (f[x]==x) return x; f[x]=find(f[x]);  return f[x]; }
double kruskal(double x){
double res=0;
for (int i=1;i<=m;i++) e1[i].val=e[i].val1-x*e[i].val2;
sort(e1+1,e1+m+1,cmp);
make_set();
for (int i=1;i<=m;i++){
int a=e[i].x,b=e[i].y,t1=find(a),t2=find(b);
if (t1!=t2){ unionn(t1,t2); res+=e1[i].val; }
}
return res;
}


void Do1(){
double l=0.0,r=10000.0,mid;
while (r-l>eps){
mid=(r+l)/2;
double t=kruskal(mid);
if (t<=0) l=mid;
else r=mid;
//cout<<l<<" "<<mid<<" "<<r<<" "<<t<<endl;
}
printf("%.3lf",r);
}


int main(){
init();
Do1();
return 0;
}

你可能感兴趣的:(未完)