結果

問題 No.177 制作進行の宮森あおいです!
ユーザー y_mazuny_mazun
提出日時 2015-04-02 23:39:35
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,001 bytes
コンパイル時間 904 ms
コンパイル使用メモリ 80,508 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-04 01:27:46
合計ジャッジ時間 1,526 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int getInt()’:
main.cpp:4:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    4 | inline int getInt(){ int s; scanf("%d", &s); return s; }
      |                             ~~~~~^~~~~~~~~~

ソースコード

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

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }
#include <queue>
#include <iostream>
#include <algorithm>
#include <set>
#include <climits>
using namespace std;
struct Edge{
int cap; // capacity
int to;
int rev; // reverse edge id
Edge(){}
Edge(int c, int t, int r) :
cap(c), to(t), rev(r){}
};
template<class E> // Edge type
class Graph{
public:
typedef std::vector<std::vector<E> > G;
private:
G g;
public:
Graph(int n) : g(G(n)) {}
void addEdge(int from, int to, int cap){
g[from].push_back(E(cap, to, g[to].size()));
g[to].push_back(E(0, from, g[from].size() - 1));
}
void addEdge(int from, int to, int cap, int cost){
g[from].push_back(E(cap, to, cost, g[to].size()));
g[to].push_back(E(0, from, -cost, g[from].size() - 1));
}
G &getRowGraph(){
return g;
}
};
template<class E>
class Dinic{
typedef typename Graph<E>::G G;
G &g;
std::size_t n; // size of graph
std::vector<int> level;
std::vector<int> iter;
// other utilities
// search length of shortest path from s
void bfs(int s){
std::queue<int> que;
level = std::vector<int>(n, -1);
level[s] = 0;
que.push(s);
while(!que.empty()){
int v = que.front(); que.pop();
for(int i = 0; i < (int)g[v].size(); i++){
E &e = g[v][i];
if(e.cap > 0 && level[e.to] < 0){
level[e.to] = level[v] + 1;
que.push(e.to);
}
}
}
}
// search path
int dfs(int v, int t, int f){
if(v == t) return f;
for(int &i = iter[v]; i < (int)g[v].size(); i++){
E &e = g[v][i];
if(e.cap > 0 && level[v] < level[e.to]){
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;
}
public:
Dinic(Graph<E> &graph) : g(graph.getRowGraph()){
n = g.size();
}
// Max flow of the flow from s to t.
int solve(int s, int t){
int flow = 0;
while(true){
int f;
bfs(s);
if(level[t] < 0) return flow;
iter = std::vector<int>(n, 0);
while((f = dfs(s, t, INT_MAX)) > 0){
flow += f;
}
}
}
};
template<class E>
int dinic(Graph<E> &g, int s, int d){
return Dinic<E>(g).solve(s, d);
}
int main(){
const int w = getInt();
const int n = getInt();
vector<int> j(n);
REP(i,n) j[i] = getInt();
const int m = getInt();
vector<int> c(m);
REP(i,m) c[i] = getInt();
vector<vector<int> > x(m, vector<int>(n));
REP(i,m){
const int q = getInt();
REP(k,q) x[i][getInt() - 1] = 1;
}
Graph<Edge> g(n + m + 2);
const int src = n + m;
const int dst = n + m + 1;
REP(i,n){
g.addEdge(src, i, j[i]);
REP(k,m) if(!x[k][i]){
g.addEdge(i, n + k, j[i]);
}
}
REP(i,m){
g.addEdge(n + i, dst, c[i]);
}
puts(dinic(g, src, dst) >= w ? "SHIROBAKO" : "BANSAKUTSUKITA");
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0