Submission #2407667


Source Code Expand

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e17;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)




class ford_fulkerson{
private:
    long long inf;  // 初期化に使う値
    struct edge {
        long long to, cap, rev;
    };
    vector<vector<edge>> list;  // グラフの隣接リスト
    vector<long long> level;    // sからの距離
    vector<long long> iter;     // どこまで調べ終わったか
public:
    ford_fulkerson(long long n, long long infinity = 1e16);    // nは頂点の数、infinityは初期化に使う値
    void add_edge(long long from, long long to, long long cap); // fromからtoへ容量capの辺をはる
    void bfs(long long s);  // sからの最短距離を求める
    long long dfs(long long v, long long t, long long f);   // 増加パスをdfsで探す
    long long max_flow(long long s, long long t);   // sからtへの最大流を求める
};

ford_fulkerson::ford_fulkerson(long long n, long long infinity){
    list.resize(n);
    level.resize(n);
    iter.resize(n);
}

void ford_fulkerson::add_edge(long long from, long long to, long long cap){
    list[from].push_back((edge){to, cap, (long long)list[to].size()});
    list[to].push_back((edge){from, 0, (long long)list[from].size() - 1});
}

void ford_fulkerson::bfs(long long s){
    for(long long i = 0; i < level.size(); i++){
        level[i] = -1;
    }
    queue<long long> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()){
        long long v = que.front(); que.pop();
        for(auto &x : list[v]){
            if(x.cap > 0 && level[x.to] < 0){
                level[x.to] = level[v] + 1;
                que.push(x.to);
            }
        }
    }
}

long long ford_fulkerson::dfs(long long v, long long t, long long f){
    if(v == t)return f;
    
    for(long long &i = iter[v]; i < list[v].size(); i++){
        edge &e = list[v][i];
        if(e.cap > 0 && level[v] < level[e.to]){
            long long d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                list[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

long long ford_fulkerson::max_flow(long long s, long long t){
    long long flow = 0;
    
    for(;;){
        bfs(s);
        if(level[t] < 0)return flow;
        
        for(long long i = 0; i < iter.size(); i++){
            iter[i] = 0;
        }
        
        long long f;
        while((f = dfs(s, t, INF)) > 0){
            flow += f;
        }
    }
}

int main() {
    ll n, g, e;
    cin >> n >> g >> e;
    
    ford_fulkerson f(n + 2);
    REP(i, g){
        ll p;
        cin >> p;
        f.add_edge(p, n + 1, 1);
    }
    REP(i, e){
        int a, b;
        cin >> a >> b;
        f.add_edge(a, b, 1);
    }
    
    cout << f.max_flow(0, n + 1) << endl;
}

Submission Info

Submission Time
Task D - 浮気予防
User chocobo
Language C++14 (GCC 5.4.1)
Score 0
Code Size 3355 Byte
Status WA
Exec Time 4 ms
Memory 640 KB

Judge Result

Set Name part All
Score / Max Score 0 / 99 0 / 1
Status
AC × 22
WA × 5
AC × 42
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, 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 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
sample_04.txt AC 1 ms 256 KB
sample_05.txt AC 1 ms 256 KB
test_01_AB.txt AC 1 ms 256 KB
test_02_AB.txt WA 1 ms 256 KB
test_03_AB.txt WA 1 ms 256 KB
test_04_AB.txt WA 1 ms 256 KB
test_05_AB.txt AC 1 ms 256 KB
test_06_AB.txt AC 1 ms 256 KB
test_07_AB.txt AC 1 ms 256 KB
test_08_AB.txt AC 1 ms 256 KB
test_09_AB.txt AC 1 ms 256 KB
test_10_AB.txt AC 1 ms 256 KB
test_11_AB.txt WA 1 ms 256 KB
test_12_AB.txt AC 1 ms 256 KB
test_13_AB.txt AC 1 ms 256 KB
test_14_AB.txt AC 1 ms 256 KB
test_15_AB.txt AC 1 ms 256 KB
test_16_AB.txt AC 1 ms 256 KB
test_17_AB.txt AC 1 ms 256 KB
test_18_AB.txt AC 1 ms 256 KB
test_19_AB.txt AC 1 ms 256 KB
test_20_AB.txt AC 1 ms 256 KB
test_21_AB.txt AC 1 ms 256 KB
test_22_AB.txt AC 1 ms 256 KB
test_23_AB.txt AC 1 ms 256 KB
test_24_AB.txt AC 1 ms 256 KB
test_25_AB.txt AC 1 ms 256 KB
test_26_A.txt WA 3 ms 640 KB
test_27_A.txt WA 3 ms 640 KB
test_28_A.txt AC 4 ms 640 KB
test_29_A.txt AC 3 ms 640 KB
test_30_A.txt AC 4 ms 640 KB
test_31_A.txt WA 3 ms 640 KB
test_32_A.txt WA 1 ms 256 KB
test_33_A.txt AC 2 ms 384 KB
test_34_A.txt AC 1 ms 256 KB
test_35_A.txt WA 2 ms 384 KB
test_36_A.txt WA 1 ms 256 KB
test_37_A.txt WA 2 ms 384 KB
test_38_A.txt WA 1 ms 256 KB
test_39_A.txt WA 1 ms 256 KB
test_40_A.txt AC 1 ms 256 KB
test_41_AB.txt AC 1 ms 256 KB
test_42_A.txt AC 2 ms 384 KB
test_43_A.txt AC 1 ms 256 KB
test_44_A.txt WA 2 ms 256 KB
test_45_A.txt WA 1 ms 256 KB
test_46_A.txt WA 1 ms 256 KB
test_47_AB.txt WA 1 ms 256 KB
test_48_A.txt AC 1 ms 256 KB
test_49_A.txt WA 1 ms 256 KB
test_50_A.txt WA 1 ms 256 KB
test_51_A.txt AC 1 ms 256 KB