結果

問題 No.177 制作進行の宮森あおいです!
ユーザー pianonekopianoneko
提出日時 2019-03-08 01:26:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,422 bytes
コンパイル時間 1,952 ms
コンパイル使用メモリ 180,212 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 19:32:06
合計ジャッジ時間 2,966 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define llINF ((long long)1e18)
#define iINF ((int)1e9)
#define ALL(obj) obj.begin(), obj.end()

using namespace std;

template <typename T>
struct Edge {
    int rev, from, to;
    T cap, icap;
    Edge(int rev, int from, int to, T cap)
        : rev(rev), from(from), to(to), cap(cap), icap(cap) {}
};

template <typename T>
struct Graph {
    vector<vector<Edge<T>>> list;
    Graph(int n = 0) : list(n) {}
    void init(int n = 0) {
        list.clear();
        list.resize(n);
    }
    inline vector<Edge<T>> &operator[](int i) { return list[i]; }
    inline const size_t size() const { return list.size(); }
    inline Edge<T> &redge(Edge<T> e) {
        if (e.from != e.to)
            return list[e.to][e.rev];
        else
            return list[e.to][e.rev + 1];
    }

    void addEdge(int from, int to, T cap) {
        list[from].push_back(Edge<T>((int)list[to].size(), from, to, cap));
        list[to].push_back(Edge<T>((int)list[from].size() - 1, to, from, 0));
    }
};

template <typename T>
struct Dinic {
    const T INF = 1 << 30;
    vector<int> level, iter;

    Dinic() {}
    void bfs(Graph<T> &graph, int s) {
        level.assign((int)graph.size(), -1);
        level[s] = 0;
        queue<int> que;
        que.push(s);
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            for (int i = 0; i < graph[v].size(); i++) {
                Edge<T> &e = graph[v][i];
                if (level[e.to] < 0 && e.cap > 0) {
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }

    T dfs(Graph<T> &graph, int v, int t, T f) {
        if (v == t) return f;
        for (int &i = iter[v]; i < graph[v].size(); i++) {
            Edge<T> &e = graph[v][i], &re = graph.redge(e);
            if (level[v] < level[e.to] && e.cap > 0) {
                T d = dfs(graph, e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    re.cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    T solve(Graph<T> &graph, int s, int t) {
        level.assign((int)graph.size(), -1);
        iter.assign((int)graph.size(), 0);
        T res = 0;
        for (;;) {
            bfs(graph, s);
            if (level[t] < 0) return res;
            for (int i = 0; i < (int)iter.size(); i++) iter[i] = 0;
            T flow = 0;
            while ((flow = dfs(graph, s, t, INF)) > 0) {
                res += flow;
            }
        }
    }
};

int main() {
    int W, N, M;
    cin >> W >> N;
    vector<int> J(N);
    REP(i, N) { cin >> J[i]; }
    cin >> M;
    vector<int> C(M);
    REP(i, M) { cin >> C[i]; }
    Graph<int> graph(110);
    REP(i, M) {
        int Q;
        cin >> Q;
        vector<bool> connect(N, true);
        REP(j, Q) {
            int X;
            cin >> X;
            connect[X - 1] = false;
        }
        REP(j, N) {
            if (!connect[j]) continue;
            graph.addEdge(j, N + i, J[j]);
        }
    }
    REP(i, N) { graph.addEdge(N + M, i, J[i]); }
    REP(i, M) { graph.addEdge(N + i, N + M + 1, C[i]); }
    Dinic<int> dinic;
    int s = N + M, t = M + N + 1;
    int ans = dinic.solve(graph, s, t);
    cout << (ans >= W ? "SHIROBAKO" : "BANSAKUTSUKITA") << endl;
}
0