最小乘积生成树板子题。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
#define rep(i,j,k) for(i=j;i<=k;++i)
#define per(i,j,k) for(i=j;i>=k;--i)
#define sqr(x) ((x)*(x))
#define G getchar()
#define LL long long
#define pll pair<LL,LL>
#define mkp make_pair
#define X first
#define Y second
#define N 205
#define NN 10005
#define inf 2550000
struct EDGE{int a,b;LL w1,w2,w;}e[NN];
int n,m,par[N],sz[N];LL ans1,ans2;
int read(){
int ch=G,x=0;
while(ch<48||ch>57)ch=G;
for(;ch>47&&ch<58;ch=G)x=x*10+ch-48;
return x;
}
bool cmp(EDGE x,EDGE y){
return x.w<y.w;
}
int getpar(int x){
if(par[x]!=x)par[x]=getpar(par[x]);
return par[x];
}
pll kruscal(){
int i,j,x,y;LL rtn1=0,rtn2=0;
rep(i,1,n)sz[par[i]=i]=1;
sort(e+1,e+m+1,cmp);
for(i=j=1;j<n;++i){
if((x=getpar(e[i].a))==(y=getpar(e[i].b)))continue;
++j;rtn1+=e[i].w1;rtn2+=e[i].w2;
if(sz[x]<sz[y])sz[par[x]=y]+=sz[x];
else sz[par[y]=x]+=sz[y];
}
if(rtn1*rtn2<ans1*ans2)ans1=rtn1,ans2=rtn2;
return mkp(rtn1,rtn2);
}
LL Cross(pll x,pll y){
return x.X*y.Y-x.Y*y.X;
}
pll operator -(pll x,pll y){
return mkp(x.X-y.X,x.Y-y.Y);
}
void solve(pll x,pll y){
int i;
rep(i,1,m)e[i].w=e[i].w2*(y.X-x.X)-e[i].w1*(y.Y-x.Y);
pll z=kruscal();
if(Cross(y-x,z-x)<0)solve(x,z),solve(z,y);
}
int main(){
int i;pll x,y;
n=read();m=read();ans1=ans2=inf;
rep(i,1,m){
e[i].a=read();e[i].b=read();e[i].w1=read();e[i].w2=read();
e[i].w=e[i].w1;++e[i].a;++e[i].b;
}
x=kruscal();
rep(i,1,m)e[i].w=e[i].w2;
y=kruscal();
solve(x,y);
printf("%lld %lld\n",ans1,ans2);
return 0;
}