結果
| 問題 |
No.957 植林
|
| コンテスト | |
| ユーザー |
shin3110
|
| 提出日時 | 2023-11-12 11:32:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,781 bytes |
| コンパイル時間 | 1,877 ms |
| コンパイル使用メモリ | 179,852 KB |
| 実行使用メモリ | 21,580 KB |
| 最終ジャッジ日時 | 2024-09-26 03:01:38 |
| 合計ジャッジ時間 | 6,373 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 1 -- * 44 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct edge {
int to, seq;
ll cup;
};
class max_flow {
public:
int siz;
vector<vector<edge>> side;
vector<bool> used;
max_flow (int n) {
siz = n;
side.assign(siz, {});
used.assign(siz, false);
return ;
}
void set(int pos, int to, ll x) {
int a = side[to].size();
int b = side[pos].size();
side[pos].push_back(edge{to, a, x});
side[to].push_back(edge{pos, b, 0});
return ;
}
ll dfs(int pos, int goal, ll F) {
if(pos == goal) return F;
used[pos] = true;
for(int i=0; i<side[pos].size(); i++) {
if(side[pos][i].cup == 0) continue;
if(used[side[pos][i].to]) continue;
ll G = dfs(side[pos][i].to, goal, min(F, side[pos][i].cup));
if(G > 0) {
side[pos][i].cup -= G;
side[side[pos][i].to][side[pos][i].seq].cup += G;
return G;
}
}
return 0;
}
ll len(int s, int t) {
ll res = 0;
while(1) {
used.assign(siz, false);
ll F = dfs(s, t, 1e18);
if(F == 0) break;
res += F;
}
return res;
}
};
signed main() {
int h, w; cin >> h >> w;
int ax = h*w+h+w+1;
max_flow F(ax+1);
for(int i=0; i<h*w; i++) {
ll g; cin >> g;
F.set(0, i+1, g);
int x = i/w;
int y = i%w;
F.set(i+1, h*w+x+1, 1e18);
F.set(i+1, h*w+h+y+1, 1e18);
}
ll ans = 0;
for(int j=h*w+1; j<=h*w+h+w; j++) {
ll r; cin >> r;
F.set(j, ax, r);
ans += r;
}
ans -= F.len(0, ax);
cout << ans << endl;
}
shin3110