結果
問題 | No.177 制作進行の宮森あおいです! |
ユーザー |
![]() |
提出日時 | 2017-07-30 01:51:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 1,944 bytes |
コンパイル時間 | 893 ms |
コンパイル使用メモリ | 93,924 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-10 20:27:59 |
合計ジャッジ時間 | 1,508 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
#include <algorithm>#include <cstdio>#include <iostream>#include <map>#include <cmath>#include <queue>#include <set>#include <sstream>#include <stack>#include <string>#include <vector>#include <stdlib.h>#include <stdio.h>#include <bitset>using namespace std;#define FOR(I,A,B) for(int I = (A); I < (B); ++I)typedef long long ll;const int inf = 1e9;// 最大流、最小カット!!!!// フォード・ファルカーソン法const int MAX_V = 110;// 行き先、容量、逆辺struct edge {int to, cap, rev;edge(int t, int c, int r) {to = t, cap = c, rev = r;}};vector<vector<edge> > G(MAX_V);bool used[MAX_V];// fromからtoへ向かう容量capの辺をグラフに追加するvoid add_edge(int from, int to, int cap) {G[from].push_back(edge(to, cap, G[to].size()));G[to].push_back(edge(from, 0, G[from].size()-1));}// 増加パスをdfsで探すint dfs(int v, int t, int f) {if(v == t) return f;used[v] = true;for(edge &e : G[v]) {if(!used[e.to] && e.cap > 0) {int d = dfs(e.to, t, min(f, e.cap));if(d > 0) {e.cap -= d;G[e.to][e.rev].cap += d;return d;}}}return 0;}int max_flow(int s, int t) {int flow = 0;for(;;) {FOR(i,0,MAX_V) used[i] = 0;int f = dfs(s, t, 1e9);if(f == 0) return flow;flow += f;}}int main(){int N, W, M;cin >> W >> N;int J[N]; FOR(i,0,N) cin >> J[i];cin >> M;int C[M]; FOR(i,0,M) cin >> C[i];bool ng[111][111];FOR(i,0,111) FOR(j,0,111) ng[i][j] = false;FOR(i,N+1,N+M+1) {int Q; cin >> Q;FOR(j,0,Q) {int in; cin >> in;ng[in][i] = true;}}FOR(i,1,N+1) add_edge(0, i, J[i-1]);FOR(i,N+1,N+M+1) add_edge(i, N+M+1, C[i-N-1]);FOR(i,1,N+1) {FOR(j,N+1,N+M+1) {if(!ng[i][j]) add_edge(i, j, inf);}}if(max_flow(0, N+M+1) >= W) puts("SHIROBAKO");else puts("BANSAKUTSUKITA");return 0;}