Submission #180672


Source Code Expand

#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstring>
using namespace std;

class Dinic {
public:
    Dinic(int nElement) {
        m_edges = vector< vector<Edge> >(nElement);
        m_level = vector<int>(nElement);
        m_iter = vector<int>(nElement);
    }
    void addEdge(int from, int to, int cap) {
        m_edges[from].push_back(Edge(to, cap, (int)m_edges[to].size()));
        m_edges[to].push_back(Edge(from, 0, (int)m_edges[from].size()-1));
    }
    int maxFlow(int s, int t) {
        int flow = 0;
        for (;;) {
            bfs(s);
            if (m_level[t] < 0) break;
            fill(m_iter.begin(), m_iter.end(), 0);
            int f = 0;
            while ((f = dfs(s, t, INF)) > 0) {
                flow += f;
            }
        }
        return flow;
    }
private:
    struct Edge {
        int to, cap, rev;
        Edge(int t, int c, int r):to(t),cap(c),rev(r){}
    };
    static const int INF = 1000000000;
    vector< vector<Edge> > m_edges;
    vector<int> m_level;
    vector<int> m_iter;
    void bfs(int s) {
        fill(m_level.begin(), m_level.end(), -1);
        m_level[s] = 0;
        queue<int> que;
        que.push(s);
        while (que.size() > 0) {
            int v = que.front(); que.pop();
            for (unsigned int i = 0; i < m_edges[v].size(); i++) {
                Edge& e = m_edges[v][i];
                if (e.cap > 0 && m_level[e.to] == -1) {
                    m_level[e.to] = m_level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }
    int dfs(int v, int t, int f) {
        if (v == t) return f;
        for (int& i = m_iter[v]; i < m_edges[v].size(); i++) {
            Edge& e = m_edges[v][i];
            if (e.cap > 0 && m_level[e.to] > m_level[v]) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    m_edges[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
};

int main() {
  int N, G, E; cin >> N >> G >> E;
  Dinic graph(N+1);
  int S = 0, T = N;
  for (int i = 0; i < G; i++) {
    int p; cin >> p;
    graph.addEdge(p, T, 1);
  }
  for (int i = 0; i < E; i++) {
    int a, b; cin >> a >> b;
    graph.addEdge(a, b, 1);
  }
  cout << graph.maxFlow(S, T) << endl;
}

Submission Info

Submission Time
Task D - 浮気予防
User fuqinho
Language C++11 (GCC 4.8.1)
Score 0
Code Size 2680 Byte
Status WA
Exec Time 32 ms
Memory 1072 KB

Judge Result

Set Name part All
Score / Max Score 0 / 99 0 / 1
Status
AC × 22
WA × 5
AC × 37
WA × 19
Set Name Test Cases
part test_01_AB.txt, test_02_AB.txt, test_03_AB.txt, test_04_AB.txt, test_05_AB.txt, test_06_AB.txt, test_07_AB.txt, test_08_AB.txt, test_09_AB.txt, test_10_AB.txt, test_11_AB.txt, test_12_AB.txt, test_13_AB.txt, test_14_AB.txt, test_15_AB.txt, test_16_AB.txt, test_17_AB.txt, test_18_AB.txt, test_19_AB.txt, test_20_AB.txt, test_21_AB.txt, test_22_AB.txt, test_23_AB.txt, test_24_AB.txt, test_25_AB.txt, test_41_AB.txt, test_47_AB.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt, test_01_AB.txt, test_02_AB.txt, test_03_AB.txt, test_04_AB.txt, test_05_AB.txt, test_06_AB.txt, test_07_AB.txt, test_08_AB.txt, test_09_AB.txt, test_10_AB.txt, test_11_AB.txt, test_12_AB.txt, test_13_AB.txt, test_14_AB.txt, test_15_AB.txt, test_16_AB.txt, test_17_AB.txt, test_18_AB.txt, test_19_AB.txt, test_20_AB.txt, test_21_AB.txt, test_22_AB.txt, test_23_AB.txt, test_24_AB.txt, test_25_AB.txt, test_26_A.txt, test_27_A.txt, test_28_A.txt, test_29_A.txt, test_30_A.txt, test_31_A.txt, test_32_A.txt, test_33_A.txt, test_34_A.txt, test_35_A.txt, test_36_A.txt, test_37_A.txt, test_38_A.txt, test_39_A.txt, test_40_A.txt, test_41_AB.txt, test_42_A.txt, test_43_A.txt, test_44_A.txt, test_45_A.txt, test_46_A.txt, test_47_AB.txt, test_48_A.txt, test_49_A.txt, test_50_A.txt, test_51_A.txt
Case Name Status Exec Time Memory
sample_01.txt AC 24 ms 916 KB
sample_02.txt AC 26 ms 924 KB
sample_03.txt AC 29 ms 796 KB
sample_04.txt AC 22 ms 916 KB
sample_05.txt AC 30 ms 888 KB
test_01_AB.txt AC 25 ms 848 KB
test_02_AB.txt WA 27 ms 888 KB
test_03_AB.txt WA 21 ms 920 KB
test_04_AB.txt WA 26 ms 880 KB
test_05_AB.txt AC 27 ms 812 KB
test_06_AB.txt AC 27 ms 916 KB
test_07_AB.txt AC 27 ms 920 KB
test_08_AB.txt AC 21 ms 920 KB
test_09_AB.txt AC 25 ms 776 KB
test_10_AB.txt AC 24 ms 736 KB
test_11_AB.txt WA 23 ms 908 KB
test_12_AB.txt AC 25 ms 732 KB
test_13_AB.txt AC 28 ms 912 KB
test_14_AB.txt AC 26 ms 892 KB
test_15_AB.txt AC 25 ms 844 KB
test_16_AB.txt AC 23 ms 916 KB
test_17_AB.txt AC 25 ms 852 KB
test_18_AB.txt AC 25 ms 920 KB
test_19_AB.txt AC 26 ms 880 KB
test_20_AB.txt AC 24 ms 780 KB
test_21_AB.txt AC 26 ms 820 KB
test_22_AB.txt AC 22 ms 920 KB
test_23_AB.txt AC 24 ms 888 KB
test_24_AB.txt AC 21 ms 920 KB
test_25_AB.txt AC 20 ms 836 KB
test_26_A.txt WA 29 ms 1032 KB
test_27_A.txt WA 28 ms 928 KB
test_28_A.txt AC 30 ms 1024 KB
test_29_A.txt AC 27 ms 1044 KB
test_30_A.txt AC 31 ms 1068 KB
test_31_A.txt WA 27 ms 1072 KB
test_32_A.txt WA 24 ms 840 KB
test_33_A.txt AC 26 ms 920 KB
test_34_A.txt AC 22 ms 916 KB
test_35_A.txt WA 27 ms 828 KB
test_36_A.txt WA 23 ms 920 KB
test_37_A.txt WA 27 ms 772 KB
test_38_A.txt WA 32 ms 884 KB
test_39_A.txt WA 27 ms 880 KB
test_40_A.txt AC 26 ms 912 KB
test_41_AB.txt AC 26 ms 848 KB
test_42_A.txt AC 25 ms 896 KB
test_43_A.txt AC 22 ms 888 KB
test_44_A.txt WA 28 ms 884 KB
test_45_A.txt WA 27 ms 884 KB
test_46_A.txt WA 24 ms 732 KB
test_47_AB.txt WA 24 ms 912 KB
test_48_A.txt AC 24 ms 836 KB
test_49_A.txt WA 27 ms 796 KB
test_50_A.txt WA 28 ms 884 KB
test_51_A.txt AC 23 ms 732 KB