20. AtCoder-Dream Team

题目链接:Dream Team

经典费用流问题。超级源点 S S S 向每个 a a a 权值连流量为 1 1 1,费用为 0 0 0 的边,每个 b b b 权值向超级汇点 T T T 连流量为 1 1 1,费用为 0 0 0 的边,对于每个人 { a i , b i , c i } \lbrace a_i,b_i,c_i \rbrace {ai,bi,ci} a i a_i ai b i b_i bi 连流量为 1 1 1,费用为 − c i -c_i ci 的边,跑最小费用最大流即可。

#include<bits/stdc++.h>
#include <atcoder/all>
#define pb push_back
#define endl '\n'
using namespace std;
using ll = long long;
const int maxn = 1e5 + 5;
const ll inf = 1e12;
int a[maxn], b[maxn], c[maxn];
void solve() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    	cin >> a[i] >> b[i] >> c[i];
    vector<ll> ans;
    for (int k = 1; k <= 150; ++k) {
    	atcoder::mcf_graph<int, ll> g(305);
    	int s = 301, t = 302;
    	for (int i = 1; i <= 150; ++i) {
        	g.add_edge(s, i, 1, 0);
        	g.add_edge(i + 150, t, 1, 0);
    	}
    	for (int i = 1; i <= n; ++i) {
       		g.add_edge(a[i], b[i] + 150, 1, inf - c[i]);
    	}
        auto now = g.flow(s, t, k);
        if (now.first < k) 
            break;
        else 
            ans.push_back(inf * k - now.second);
    }
    cout << ans.size() << endl;
    for (auto i : ans) 
        cout << i << endl;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值