题目
思路
然后就是求下凸壳上
x
y
xy
xy 最小值
代码
#include<set>
#include<map>
#include<cmath>
#include<deque>
#include<stack>
#include<ctime>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<climits>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
bool f=0;int x=0;char c=getchar();
while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
return !f?x:-x;
}
#define fi first
#define se second
#define mp make_pair
const int MAXN=200;
const int MAXM=10000;
const LL INF=10000000000000000ll;
struct Edge{
int u,v;
LL a,b,w;
friend bool operator < (Edge a,Edge b){return a.w<b.w;}
}edge[MAXM+5];
int n,m;
int fa[MAXN+5];
LL ans,ansx,ansy;
int Find(int u){return fa[u]==u?u:(fa[u]=Find(fa[u]));}
void MST(LL ka,LL kb,LL &rx,LL &ry){
rx=0,ry=0;
for(int i=1;i<=m;i++)
edge[i].w=ka*edge[i].a+kb*edge[i].b;
sort(edge+1,edge+m+1);
for(int i=1;i<=n;i++)
fa[i]=i;
for(int i=1;i<=m;i++){
int u=edge[i].u,v=edge[i].v;
int fu=Find(u),fv=Find(v);
if(fu==fv) continue;
fa[fu]=fv;
rx+=edge[i].a,ry+=edge[i].b;
}
if(rx*ry<ans||(rx*ry==ans&&rx<ansx)) ans=rx*ry,ansx=rx,ansy=ry;
return ;
}
void Solve(LL ax,LL ay,LL bx,LL by){
LL rx,ry;
MST(ay-by,bx-ax,rx,ry);
if((ay-by)*rx+(bx-ax)*ry-bx*ay+ax*by<0)
Solve(ax,ay,rx,ry),Solve(rx,ry,bx,by);
return ;
}
int main(){
ans=INF;
n=read(),m=read();
for(int i=1;i<=m;i++){
int u=read()+1,v=read()+1,a=read(),b=read();
edge[i]=(Edge){u,v,a,b,0};
}
LL ax,ay,bx,by;
MST(1,0,ax,ay);
MST(0,1,bx,by);
Solve(ax,ay,bx,by);
printf("%lld %lld\n",ansx,ansy);
return 0;
}