社区讨论
67ptas求条,WA#1#3#8
P1361小M的作物参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mjnq20tw
- 此快照首次捕获于
- 2025/12/27 11:09 2 个月前
- 此快照最后确认于
- 2025/12/28 23:35 2 个月前
CPP
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
namespace betcoder {
void Fill(int Array[], int Left, int Right, int Value) {
for (int i = Left; i <= Right; i++) {
Array[i] = Value;
}
}
ll rint() {
ll x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') (ch == '-') ? f = -1 : f = f,ch = getchar();
while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return x * f;
}
#define rep(x,y,z,w) for(int x = y;x <= z;x += w)
#define per(x,y,z,w) for(int x = y;x >= z;x -= w)
};
const int M = 5e6 + 5;
const int inf = 0x3f3f3f3f;
using namespace betcoder;
int n,m;
struct node{
ll u,w,o;
};
int S,T;
int dis[M], gap[M];
vector <node> v[M];
ll dfs(int x, ll mx) {
if (x == T) {
return mx;
}
ll sum = 0;
int minn = T + 1;
for (int j = 0; j < v[x].size(); j++) {
auto i = v[x][j];
if (i.w <= 0) continue;
if (dis[x] == dis[i.u] + 1) {
int res = min(mx - sum, i.w);
res = dfs(i.u, res);
v[x][j].w -= res;
v[i.u][i.o].w += res;
sum += res;
if (dis[S] >= T + 1) return sum;
if (sum == mx) break;
}
minn = min(minn, dis[i.u]);
}
if (sum == 0) {
gap[dis[x]]--;
if (gap[dis[x]] == 0) dis[0] = T + 2;
dis[x] = minn + 1;
gap[dis[x]]++;
}
return sum;
}
void addedge(int x, int y, int z) {
v[x].push_back({y, z, (int)v[y].size()});
v[y].push_back({x, 0, (int)v[x].size() - 1});
}
ll ans;
signed main() {
n = rint();
S = 0,T = n + 2 * m + 1;
int siz = n;
rep(i,1,n,1) {
int x = rint();
ans += x;
addedge(i,T,x);
}
rep(i,1,n,1) {
int x = rint();
ans += x;
addedge(S,i,x);
}
int m = rint();
rep(i,1,m,1) {
int k = rint(),x = rint(),y = rint();
ans += x;
ans += y;
siz += 2;
while(k--) {
int a = rint();
addedge(siz-1,a,inf);
addedge(a,siz,inf);
}
addedge(S,siz-1,y);
addedge(siz,T,x);
}
while(dis[0] < T + 2) {
ll res = dfs(S,inf);
ans -= res;
}
cout << ans;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...