Submission #1768566


Source Code Expand

#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

struct Graph{
    struct Node{
        vector<int> inEdges, outEdges;
        vector<int>& edges(bool rev = false){ return rev ? inEdges : outEdges; }
    };
    struct Edge{
        int from, dest;
        ll limit, rem;
        Edge(){ }
        Edge(int from, int dest, ll limit = 1): from(from), dest(dest), limit(limit), rem(limit){ }
        int to(bool rev = false){ return rev ? from : dest; }
        ll remain(bool rev = false){ return rev ? limit - rem : rem; }
        void pour(ll qua, bool rev = false){ rem -= rev ? - qua : qua; }
    };
    vector<Node> nodes;
    vector<Edge> edges;
    Graph(int nn, int en = 10): nodes(nn){
        edges.reserve(en);
    }

    void addEdge(int from, int dest, ll limit){
        nodes[from].outEdges.emplace_back(edges.size());
        nodes[dest].inEdges.emplace_back(edges.size());
        edges.emplace_back(from, dest, limit);
    }
    ll flow(int start, int goal, vector<char>& visited, ll cur){
        if(start == goal){ return cur; }
        auto _flow = [&](bool rev = false){
            for(int eidx : nodes[start].edges(rev)){
                Edge& e = edges[eidx];
                int vidx = e.to(rev);
                if(!e.remain(rev) || visited[vidx]){ continue; }
                visited[vidx] = true;
                ll lim = min(cur, e.remain(rev));
                if((lim = flow(vidx, goal, visited, lim))){
                    e.pour(lim, rev);
                    return lim;
                }
            }
            return 0ll;
        };
        ll ret = _flow();
        return ret ? ret : _flow(true);
    }
    ll maxFlow(int start, int goal){
        if(start == goal){ exit(1); }
        ll ret = 0;
        while(1){
            ll prev = ret;
            vector<char> visited(nodes.size());
            ret += flow(start, goal, visited, MLL);
            if(ret == prev){ break; }
        }
        return ret;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, g, e;
    cin >> n >> g >> e;
    Graph gr(n + 1);
    for(int i = 0; i < g; i++){
        int p; cin >> p;
        gr.addEdge(p, n, 1);
    }
    for(int i = 0; i < e; i++){
        int a, b;
        cin >> a >> b;
        gr.addEdge(a, b, 1);
        gr.addEdge(b, a, 1);
    }
    cout << gr.maxFlow(0, n) << '\n';
}

Submission Info

Submission Time
Task D - 浮気予防
User sumoooru
Language C++14 (Clang 3.8.0)
Score 100
Code Size 3039 Byte
Status AC
Exec Time 7 ms
Memory 716 KB

Judge Result

Set Name part All
Score / Max Score 99 / 99 1 / 1
Status
AC × 27
AC × 61
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 AC 1 ms 256 KB
test_03_AB.txt AC 1 ms 256 KB
test_04_AB.txt AC 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 AC 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 AC 7 ms 716 KB
test_27_A.txt AC 7 ms 716 KB
test_28_A.txt AC 7 ms 716 KB
test_29_A.txt AC 7 ms 716 KB
test_30_A.txt AC 7 ms 716 KB
test_31_A.txt AC 7 ms 716 KB
test_32_A.txt AC 2 ms 384 KB
test_33_A.txt AC 4 ms 512 KB
test_34_A.txt AC 2 ms 256 KB
test_35_A.txt AC 2 ms 384 KB
test_36_A.txt AC 2 ms 256 KB
test_37_A.txt AC 3 ms 512 KB
test_38_A.txt AC 1 ms 256 KB
test_39_A.txt AC 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 4 ms 512 KB
test_43_A.txt AC 1 ms 256 KB
test_44_A.txt AC 2 ms 384 KB
test_45_A.txt AC 1 ms 256 KB
test_46_A.txt AC 1 ms 256 KB
test_47_AB.txt AC 1 ms 256 KB
test_48_A.txt AC 1 ms 256 KB
test_49_A.txt AC 1 ms 256 KB
test_50_A.txt AC 1 ms 256 KB
test_51_A.txt AC 1 ms 256 KB