Analysis
学习ing
最小乘积生成树
Code
/*
created by xly
*/
#include<bits/stdc++.h>
#define in red()
#define re register
using namespace std;
inline int red(){
char ch;int f=1,res=0;
while((ch=getchar())<'0'||ch>'9') if(ch=='-') f=-1;
while(ch>='0'&&ch<='9'){
res=(res<<1)+(res<<3)+(ch^48);
ch=getchar();
}
return f==1?res:-res;
}
const int N=205,M=10009;
struct EDGE{
int u,v,c,t,w;
void read(){u=in;v=in;c=in;t=in;}
bool operator <(const EDGE &a){ return w<a.w;}
}edge[M];
struct POINT{
int x,y;
POINT(int _x=0,int _y=0):x(_x),y(_y){}
POINT operator -(const POINT &a){
POINT c;
c.x=x-a.x;c.y=y-a.y;
return c;
}
}minc,mint,ans;
int cross(POINT a,POINT b){
return a.x*b.y-a.y*b.x;
}
int n,m,fa[N];
inline int getfa(int x){return x==fa[x]?x:fa[x]=getfa(fa[x]);}
inline POINT Kruscal(){
for(re int i=0;i<=n;++i) fa[i]=i;
int t=0;
POINT now;
for(re int i=1;i<=m;++i){
int u=getfa(edge[i].u),v=getfa(edge[i].v);
if(u!=v){
fa[u]=v;
now.x+=edge[i].c;
now.y+=edge[i].t;
t++;
if(t==n-1) break;
}
}
long long ANS=ans.x*1ll*ans.y,NOW=now.x*1ll*now.y;
if(ANS>NOW||(ANS==NOW&&ans.x>now.x)) ans=now;
return now;
}
void work(POINT a,POINT b){
for(re int i=1;i<=m;++i) edge[i].w=edge[i].t*(b.x-a.x)-edge[i].c*(b.y-a.y);
sort(edge+1,edge+m+1);
POINT c=Kruscal();
if(cross(b-a,c-a)>=0) return;
work(a,c);
work(c,b);
}
int main(){
n=in;m=in;
ans.x=1e9;ans.y=1e9;
for(re int i=1;i<=m;++i) edge[i].read();
for(re int i=1;i<=m;++i) edge[i].w=edge[i].c;
sort(edge+1,edge+m+1);
minc=Kruscal();
for(re int i=1;i<=m;++i) edge[i].w=edge[i].t;
sort(edge+1,edge+m+1);
mint=Kruscal();
work(minc,mint);
printf("%d %d",ans.x,ans.y);
return 0;
}