ABC247G 题解
sunkuangzheng · · 题解
- 平面中有
n 个点,坐标为(a_i,b_i) ,权值为c_i 。每一行每一列最多只能选一个点,最大化选点个数k 并输出。- 同时对于
i \in [1,k] ,最大化选出i 个点的权值和。
对于一个点
考虑第二问其实就是二分图最大权匹配,直接暴力跑
使用 acl 的费用流,单次时间复杂度为
#include<bits/stdc++.h>
#include <atcoder/all>
using ll = long long;
const int N = 5e5+5;
const ll inf = 1e10;
using namespace std;
using namespace atcoder;
int T,n,a[N],b[N],c[N],s,ss,tt,x;
int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> n;
for(int i = 1;i <= n;i ++) cin >> a[i] >> b[i] >> c[i];
auto build = [&](int lim){
mcf_graph<int,ll> g(302);
ss = 0,tt = 301;
for(int i = 1;i <= 150;i ++) g.add_edge(ss,i,1,0),g.add_edge(i+150,tt,1,0);
for(int i = 1;i <= n;i ++) g.add_edge(a[i],b[i]+150,1,inf - c[i]);
return g.flow(ss,tt,lim);
};
cout << (x = build(1e9).first) << "\n";
for(int i = 1;i <= x;i ++) cout << - build(i).second + inf * i << "\n";
}