結果

問題 No.177 制作進行の宮森あおいです!
ユーザー chocobo
提出日時 2020-05-07 20:39:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 3,228 bytes
コンパイル時間 2,051 ms
コンパイル使用メモリ 133,896 KB
最終ジャッジ日時 2025-01-10 07:31:50
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define REP(i, n) for(ll i = 0; i < n; i++)
class Dinic {
private:
struct edge {
ll to, cap, rev;
};
vector<vector<edge>> list; //
vector<ll> level; // s
vector<ll> iter; // 調
public:
Dinic(ll n) : list(n), level(n), iter(n){}
void add_edge(ll from, ll to, ll cap){
list[from].push_back({to, cap, (ll)list[to].size()});
list[to].push_back({from, 0, (ll)list[from].size() - 1});
}
void bfs(ll s){
level.assign(level.size(), -1);
queue<ll> que;
level[s] = 0;
que.push(s);
while(!que.empty()){
ll v = que.front(); que.pop();
for(auto &x : list[v]){
if(x.cap > 0 && level[x.to] < 0){
level[x.to] = level[v] + 1;
que.push(x.to);
}
}
}
}
ll dfs(ll v, ll t, ll f){
if(v == t) return f;
for(ll &i = iter[v]; i < list[v].size(); i++){
edge &e = list[v][i];
if(e.cap > 0 && level[v] < level[e.to]){
ll d = dfs(e.to, t, min(f, e.cap));
if(d > 0){
e.cap -= d;
list[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
ll max_flow(ll s, ll t){
ll flow = 0;
for(;;){
bfs(s);
if(level[t] < 0) return flow;
iter.assign(iter.size(), 0);
ll f;
while((f = dfs(s, t, INF)) > 0){
flow += f;
}
}
}
};
int main(){
ll w, n;
cin >> w >> n;
vector<ll> J(n);
REP(i, n){
cin >> J[i];
}
ll m;
cin >> m;
vector<ll> c(m);
REP(i, m){
cin >> c[i];
}
vector<vector<ll>> x(m);
REP(i, m){
ll q;
cin >> q;
x[i].resize(q);
REP(j, q){
cin >> x[i][j];
x[i][j]--;
}
}
Dinic dic(n + m + 2);
const ll s = n + m, g = n + m + 1;
REP(i, n){
dic.add_edge(s, i, J[i]);
}
REP(i, m){
dic.add_edge(n + i, g, c[i]);
}
REP(i, n){
REP(j, m){
bool ok = true;
REP(k, x[j].size()){
if(x[j][k] == i){
ok = false;
break;
}
}
if(ok){
dic.add_edge(i, n + j, J[i]);
}
}
}
cout << ((dic.max_flow(s, g) >= w)? "SHIROBAKO" : "BANSAKUTSUKITA") << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0