結果
| 問題 |
No.177 制作進行の宮森あおいです!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-01-16 02:19:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,945 bytes |
| コンパイル時間 | 766 ms |
| コンパイル使用メモリ | 80,544 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-19 19:49:29 |
| 合計ジャッジ時間 | 1,544 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
ソースコード
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
typedef long long ll;
using namespace std;
ll maximum_flow(int s, int t, vector<vector<ll> > const & g /* capacity, adjacency matrix */) { // edmonds karp, O(E^2V)
int n = g.size();
vector<vector<ll> > flow(n, vector<ll>(n));
auto residue = [&](int i, int j) { return g[i][j] - flow[i][j]; };
ll result = 0;
while (true) {
vector<int> prev(n, -1);
vector<ll> f(n);
// find the shortest augmenting path
queue<int> q; // bfs
q.push(s);
while (not q.empty()) {
int i = q.front(); q.pop();
repeat (j,n) if (prev[j] == -1 and j != s and residue(i,j) > 0) {
prev[j] = i;
f[j] = residue(i,j);
if (i != s) f[j] = min(f[j], f[i]);
q.push(j);
}
}
if (prev[t] == -1) break; // not found
// backtrack
for (int i = t; prev[i] != -1; i = prev[i]) {
int j = prev[i];
flow[j][i] += f[t];
flow[i][j] -= f[t];
}
result += f[t];
}
return result;
}
int main() {
// input
int w, n; cin >> w >> n;
vector<int> j(n); repeat (i,n) cin >> j[i];
int m; cin >> m;
vector<int> c(m); repeat (i,m) cin >> c[i];
vector<set<int> > x(m);
repeat (i,m) {
int q; cin >> q;
repeat (j,q) {
int y; cin >> y;
x[i].insert(y-1);
}
}
// make a capacity graph
const ll INF = 1000000007;
vector<vector<ll> > g(n+m+2, vector<ll>(n+m+2));
int s = n+m, t = n+m+1;
repeat (i,n) g[s][i] = j[i];
repeat (j,m) g[n+j][t] = c[j];
repeat (j,m) repeat (i,n) if (not x[j].count(i)) g[i][n+j] = INF;
// output
cout << (maximum_flow(s,t,g) >= w ? "SHIROBAKO" : "BANSAKUTSUKITA") << endl;
return 0;
}