2395: [Balkan 2011]Timeismoney

推荐一篇炒鸡强的blog
好就这样…不想写其他的,看这个就ojbk了
c++代码如下:

#include<bits/stdc++.h>
#define rep(i,x,y) for(register int i = x; i <= y; ++ i)
#define repd(i,x,y) for(register int i = x; i >= y; -- i)
using namespace std;
typedef long long ll;
template<typename T>inline void read(T&x)
{
    x = 0;char c;int sign = 1;
    do { c = getchar(); if(c == '-') sign = -1; }while(!isdigit(c));
    do { x = x * 10 + c - '0'; c = getchar(); }while(isdigit(c));
    x *= sign;
}

const int N = 1e4 + 50;
struct Edge { int u,v,c,t,w; }edge[N];
struct Point { int x,y; }A,B,ans;
bool operator < (const Edge a,const Edge b) { return a.w < b.w; }
int n,m,f[N];

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

inline void solve(Point&a)
{
    a.x = a.y = 0;
    rep(i,1,n) f[i] = i;
    sort(edge + 1,edge + 1 + m);
    rep(i,1,m)
    {
        int x = find(edge[i].u),y = find(edge[i].v);
        if(x != y)
        {
            f[x] = y;
            a.x += edge[i].c;
            a.y += edge[i].t;
        }
    }
    if(1ll * a.x * a.y < 1ll * ans.x * ans.y || (a.x * a.y == ans.x * ans.y &&  a.x < ans.x))
        ans = a;
}

ll cross(Point A,Point B) { return A.x * B.y - B.x * A.y; }

void work(Point A,Point B)
{
    Point C;
    rep(i,1,m) edge[i].w = edge[i].c* (A.y - B.y) + edge[i].t *(B.x-A.x);
    solve(C);
    if(cross((Point){C.x - A.x,C.y - A.y},(Point){B.x - A.x,B.y - A.y}) <= 0)
        return;
    work(A,C);
    work(C,B);
}

int main()
{
    ans.x = 1e9+7; ans.y = 1e9+7;
    read(n); read(m);
    rep(i,1,m)
        read(edge[i].u), read(edge[i].v),
        read(edge[i].c),read(edge[i].t),
        ++edge[i].u,++edge[i].v;

    rep(i,1,m) edge[i].w = edge[i].c;
    solve(A);
    rep(i,1,m) edge[i].w = edge[i].t;
    solve(B);

    work(A,B);
    cout << ans.x << ' ' << ans.y;

    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值