結果

問題 No.177 制作進行の宮森あおいです!
ユーザー tottoripaper
提出日時 2015-07-19 19:11:57
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,469 bytes
コンパイル時間 484 ms
コンパイル使用メモリ 58,116 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-08 10:22:39
合計ジャッジ時間 1,086 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:82:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   82 |     scanf("%d", &W);
      |     ~~~~~^~~~~~~~~~
main.cpp:83:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   83 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
main.cpp:85:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   85 |         scanf("%d", J+i);
      |         ~~~~~^~~~~~~~~~~
main.cpp:87:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   87 |     scanf("%d", &M);
      |     ~~~~~^~~~~~~~~~
main.cpp:89:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   89 |         scanf("%d", C+i);
      |         ~~~~~^~~~~~~~~~~
main.cpp:102:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  102 |         scanf("%d", &q);
      |         ~~~~~^~~~~~~~~~
main.cpp:109:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  109 |             scanf("%d", &x);
      |             ~~~~~^~~~~~~~~~

ソースコード

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

// Edmonds-Karp
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <tuple>
#include <queue>
typedef std::tuple<int,int,int> P;
const int INF = 1001001001;
int W, N, M;
int J[51], C[51];
// [0, N):
// [N, N+M):
// N+M:
// N+M+1:
std::vector<P> G[200];
bool visited[200];
int prevVertex[200], prevIndex[200], mns[200];
void addEdge(int from, int to, int cap){
G[from].emplace_back(to, cap, G[to].size());
G[to].emplace_back(from, 0, G[from].size()-1);
}
int bfs(){
std::fill(visited, visited+200, false);
std::fill(mns, mns+200, INF);
std::queue<int> queue;
queue.push(N+M);
visited[N+M] = true;
while(!queue.empty()){
int u = queue.front();
queue.pop();
if(u == N+M+1){break;}
for(int i=0;i<(int)G[u].size();i++){
int to, cap;
std::tie(to, cap, std::ignore) = G[u][i];
if(visited[to]){continue;}
if(cap == 0){continue;}
visited[to] = true;
prevVertex[to] = u;
prevIndex[to] = i;
mns[to] = std::min(mns[u], cap);
queue.push(to);
}
}
if(!visited[N+M+1]){return 0;}
int f = mns[N+M+1];
for(int u=N+M+1;u!=N+M;){
int pv = prevVertex[u],
pi = prevIndex[u];
std::get<1>(G[pv][pi]) -= f;
std::get<1>(G[u][std::get<2>(G[pv][pi])]) += f;
u = pv;
}
return f;
}
int maxFlow(){
int f = 0;
while(1){
int x = bfs();
if(x == 0){return f;}
f += x;
}
}
int main(){
scanf("%d", &W);
scanf("%d", &N);
for(int i=0;i<N;i++){
scanf("%d", J+i);
}
scanf("%d", &M);
for(int i=0;i<M;i++){
scanf("%d", C+i);
}
for(int i=0;i<M;i++){
addEdge(i+N, N+M+1, C[i]);
}
for(int i=0;i<N;i++){
addEdge(N+M, i, J[i]);
}
for(int i=0;i<M;i++){
int q;
scanf("%d", &q);
bool flags[51];
std::fill(flags, flags+51, false);
for(int j=0;j<q;j++){
int x;
scanf("%d", &x);
x -= 1;
flags[x] = true;
}
for(int j=0;j<N;j++){
if(flags[j]){continue;}
addEdge(j, i+N, J[j]);
}
}
// printf("%d\n", maxFlow());
if(maxFlow() >= W){puts("SHIROBAKO");}
else{puts("BANSAKUTSUKITA");}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0