結果
問題 | No.177 制作進行の宮森あおいです! |
ユーザー |
![]() |
提出日時 | 2022-04-13 12:13:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 2,197 bytes |
コンパイル時間 | 2,431 ms |
コンパイル使用メモリ | 180,668 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 08:45:37 |
合計ジャッジ時間 | 3,210 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
コンパイルメッセージ
main.cpp: In function 'void add_edge(ll, ll, ll)': main.cpp:18:41: warning: narrowing conversion of '(& G.std::vector<std::vector<edge> >::operator[](((std::vector<std::vector<edge> >::size_type)to)))->std::vector<edge>::size()' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'll' {aka 'long long int'} [-Wnarrowing] 18 | G[from].push_back({to,cap,G[to].size()}); | ~~~~~~~~~~^~ main.cpp:19:43: warning: narrowing conversion of '((& G.std::vector<std::vector<edge> >::operator[](((std::vector<std::vector<edge> >::size_type)from)))->std::vector<edge>::size() - 1)' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'll' {aka 'long long int'} [-Wnarrowing] 19 | G[to].push_back({from,0,G[from].size()-1}); | ~~~~~~~~~~~~~~^~
ソースコード
#include <bits/stdc++.h>using namespace std;using ll =long long;#define all(v) v.begin(),v.end()#define rep(i,a,b) for(int i=a;i<b;i++)#define rrep(i,a,b) for(int i=a;i>=b;i--)ll INF=2e18;struct edge {ll to,cap,rev;};ll V;vector<vector<edge>> G;vector<ll> level;vector<ll> iter;void add_edge( ll from,ll to,ll cap){G[from].push_back({to,cap,G[to].size()});G[to].push_back({from,0,G[from].size()-1});}void bfs(ll s) {level=vector<ll> (V,-1);queue<ll> que;level[s]=0;que.push(s);while(!que.empty()) {ll v=que.front();que.pop();for(ll i=0;i<G[v].size();i++) {edge &e=G[v][i];if(e.cap>0&&level[e.to]<0) {level[e.to]=level[v]+1;que.push(e.to);}}}}ll dfs(ll v,ll t,ll f) {if(v==t) return f;for(ll &i=iter[v];i<G[v].size();i++) {edge &e=G[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;G[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=vector<ll> (V,0);ll f;while((f=dfs(s,t,INF))>0) {flow+=f;}}}int main() {ll W;cin>>W;ll N;cin>>N;vector<ll> J(N);for(ll i=0;i<N;i++) cin>>J[i];ll M;cin>>M;vector<ll> C(M);for(ll i=0;i<M;i++) cin>>C[i];V=N+M+2;G=vector<vector<edge>> (V,vector<edge> (0));for(ll i=0;i<N;i++) {add_edge(0,i+1,J[i]);}for(ll i=0;i<M;i++){add_edge(N+i+1,N+M+1,C[i]);}for(ll i=0;i<M;i++) {ll Q;cin>>Q;vector<bool> note(N,false);for(ll j=0;j<Q;j++) {ll X;cin>>X;note[X-1]=true;}for(ll j=0;j<N;j++) {if(note[j]) continue;add_edge(j+1,N+i+1,INF);}}ll ans=max_flow(0,N+M+1);if(ans>=W) cout<<"SHIROBAKO"<<endl;else cout<<"BANSAKUTSUKITA"<<endl;}