Language: C++

#include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <tuple>



template <typename TValue>
class MyFlowNetworkIterator;

template <typename TValue>
class MyFlowNetworkIteratorOut;

template <typename TValue>
class MyFlowNetworkIteratorIn;





template <typename TValue>
class MyFlowNetwork
{
public:

    using ValueType = TValue;
    using OutIterator = MyFlowNetworkIteratorOut<TValue>;
    using InIterator = MyFlowNetworkIteratorIn<TValue>;

    friend MyFlowNetworkIterator<TValue>;
    friend MyFlowNetworkIteratorOut<TValue>;
    friend MyFlowNetworkIteratorIn<TValue>;

    MyFlowNetwork(const MyFlowNetwork<TValue> & other) = default;
    MyFlowNetwork(MyFlowNetwork<TValue> && other) noexcept = default;
    MyFlowNetwork& operator=(const MyFlowNetwork<TValue> & other) = default;
    MyFlowNetwork& operator=(MyFlowNetwork<TValue> && other) noexcept = default;
    ~MyFlowNetwork() = default;

    MyFlowNetwork(std::size_t size, std::size_t s, std::size_t t,
                  const std::vector<std::vector<TValue>>& startmatrix);

    MyFlowNetworkIteratorOut<TValue> begin_out(std::size_t vertex_number);
    MyFlowNetworkIteratorOut<TValue> end_out(std::size_t vertex_number);

    MyFlowNetworkIteratorIn<TValue> begin_in(std::size_t vertex_number);
    MyFlowNetworkIteratorIn<TValue> end_in(std::size_t vertex_number);



    std::size_t get_source();
    std::size_t get_stock();
    std::size_t get_size();

private:

    struct Edge
    {
        TValue _capacity;
        TValue _flow;
        std::size_t _end;
        std::size_t _prevedgeindex;
    };


    static const std::size_t _INFSIZE;
    std::size_t _size;
    std::size_t _s;
    std::size_t _t;
    std::vector<std::size_t> _endpoints;
    std::vector<Edge> _edges;
    void _addedge(std::size_t start, std::size_t end, const TValue& capacity);
};

template< typename  TValue>
const std::size_t MyFlowNetwork<TValue>::_INFSIZE =
        std::numeric_limits<std::size_t>::max();







template <typename TValue>
class MyFlowNetworkIterator
{
public:

    using ValueType = typename MyFlowNetwork<TValue>::ValueType ;

    MyFlowNetworkIterator(MyFlowNetwork<TValue> * net, std::size_t vertex_num, bool is_end);

    MyFlowNetworkIterator() = default;
    MyFlowNetworkIterator(const MyFlowNetworkIterator<TValue> & other) = default;
    MyFlowNetworkIterator(MyFlowNetworkIterator<TValue> && other) noexcept = default;
    MyFlowNetworkIterator& operator= (const MyFlowNetworkIterator<TValue> & other) = default;
    MyFlowNetworkIterator& operator= (MyFlowNetworkIterator<TValue> && other) noexcept = default;
    ~MyFlowNetworkIterator() = default;

    bool operator==(const MyFlowNetworkIterator &rhs);

    bool operator!=(const MyFlowNetworkIterator &rhs);

    TValue get_capacity();
    TValue get_flow();
    TValue get_rem_capacity();
    std::size_t get_startpoint();
    std::size_t get_endpoint();
    bool is_ended();

    void push_flow_r(const TValue& flow);

protected:

    bool _is_end = true;
    MyFlowNetwork<TValue>* _net = nullptr;
    std::size_t _curr_edge_num = 0;
};

template <typename TValue>
class MyFlowNetworkIteratorOut:public MyFlowNetworkIterator<TValue>
{
public:

    MyFlowNetworkIteratorOut() = default;
    MyFlowNetworkIteratorOut(MyFlowNetwork<TValue> * net, std::size_t vertex_num, bool is_end);

    MyFlowNetworkIteratorOut<TValue>& operator++();
};

template <typename TValue>
class MyFlowNetworkIteratorIn:public MyFlowNetworkIterator<TValue>
{
public:

    MyFlowNetworkIteratorIn() = default;
    MyFlowNetworkIteratorIn(MyFlowNetwork<TValue> * net, std::size_t vertex_num, bool is_end);
    MyFlowNetworkIteratorIn<TValue>& operator++();

protected:
    void make_xor_safe();
};







template<typename NetIterator>
typename NetIterator::ValueType flowsumm(NetIterator&& start, NetIterator&& end);


template<typename Network>
class MalhotraPerformer
{
public:

    using ValueType = typename Network::ValueType;
    MalhotraPerformer() = default;
    MalhotraPerformer(const MalhotraPerformer<Network> & other) = delete;
    MalhotraPerformer(MalhotraPerformer<Network> && other) noexcept = delete;
    MalhotraPerformer& operator= (const MalhotraPerformer<Network> & other) = delete;
    MalhotraPerformer& operator= (MalhotraPerformer<Network> && other) noexcept = delete;

    void push_maxflow(Network* net);

    ~MalhotraPerformer() = default;
private:

    void _initialize(Network* net);
    void _main_cycle();
    void _deinitialize();

    void _find_blokflow_in_layer();
    void _estimate_layers();
    void _prepare_iteration();
    void _delete_vertex(std::size_t vertex_num);
    void _push_flow_to_left(ValueType val, std::size_t vertex_number);
    void _push_flow_to_right(ValueType val, std::size_t vertex_number);
    bool _is_source_or_stock(std::size_t vertex_num);


    template<typename  Func1, typename Func2>
    void _count_potential(std::vector<ValueType>& potentials, Func1 func_begin, Func2 func_end);

    template <typename NetIterator>
    bool _is_in_lnet(NetIterator&& it);

    Network* _net = nullptr;
    std::vector<long long> _bfs_heights;
    std::vector<ValueType> _rightpotentials;
    std::vector<ValueType> _leftpotentials;
    std::vector<typename Network::InIterator> _initerators;
    std::vector<typename Network::OutIterator> _outiterators;
    std::vector<bool> _is_deleted;
};












/////////////////////////////////////////////////////////////////////////
/////////////Implementation//////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////

/////////////////MyFlowNetwork///////////////////////////////////////////
template <typename TValue>
MyFlowNetwork<TValue>::MyFlowNetwork(std::size_t size, std::size_t s, std::size_t t,
                                     const std::vector<std::vector<TValue>>& startmatrix)
        :_size(size), _s(s), _t(t),
         _endpoints(std::vector<std::size_t>(size, std::numeric_limits<std::size_t>::max()))
{
    for(std::size_t i = 0; i < _size; ++i)
        for(std::size_t j = i+1; j < _size; ++j)
            if(startmatrix[i][j] != 0 || startmatrix[j][i] != 0)
            {
                this->_addedge(i, j, startmatrix[i][j]);
                this->_addedge(j, i, startmatrix[j][i]);
            }
}

template <typename TValue>
MyFlowNetworkIteratorOut<TValue> MyFlowNetwork<TValue>::begin_out(std::size_t vertex_number)
{
    return MyFlowNetworkIteratorOut<TValue>(this, vertex_number, false);
}

template <typename TValue>
MyFlowNetworkIteratorOut<TValue> MyFlowNetwork<TValue>::end_out(std::size_t vertex_number)
{
    return MyFlowNetworkIteratorOut<TValue>(this, vertex_number, true);
}

template <typename TValue>
MyFlowNetworkIteratorIn<TValue> MyFlowNetwork<TValue>::begin_in(std::size_t vertex_number)
{
    return MyFlowNetworkIteratorIn<TValue>(this, vertex_number, false);
}

template <typename TValue>
MyFlowNetworkIteratorIn<TValue> MyFlowNetwork<TValue>::end_in(std::size_t vertex_number)
{
    return MyFlowNetworkIteratorIn<TValue>(this, vertex_number, true);
}

template <typename TValue>
std::size_t MyFlowNetwork<TValue>::get_source()
{
    return _s;
}

template <typename TValue>
std::size_t MyFlowNetwork<TValue>::get_stock()
{
    return _t;
}

template <typename TValue>
std::size_t MyFlowNetwork<TValue>::get_size()
{
    return _size;
}

template <typename TValue>
void MyFlowNetwork<TValue>::_addedge(std::size_t start, std::size_t end, const TValue& capacity)
{

    Edge newadge({capacity, 0, end, _endpoints[start]});
    _endpoints[start] = _edges.size();
    _edges.push_back(newadge);
}






/////////////////MyFlowNetworkIterator///////////////////////////////////////////

template <typename TValue>
MyFlowNetworkIterator<TValue>::MyFlowNetworkIterator(MyFlowNetwork<TValue> *net, std::size_t vertex_num, bool is_end):
        _net(net), _curr_edge_num(net->_endpoints[vertex_num]), _is_end(is_end)
{}


template <typename TValue>
TValue MyFlowNetworkIterator<TValue>::get_capacity()
{
    if(_is_end)
        throw;
    return _net->_edges[_curr_edge_num]._capacity;
}

template <typename TValue>
TValue MyFlowNetworkIterator<TValue>::get_rem_capacity()
{
    if(_is_end)
        throw;
    return _net->_edges[_curr_edge_num]._capacity - _net->_edges[_curr_edge_num]._flow;
}

template <typename TValue>
TValue MyFlowNetworkIterator<TValue>::get_flow()
{
    if(_is_end)
        throw;
    return _net->_edges[_curr_edge_num]._flow;
}

template <typename TValue>
std::size_t MyFlowNetworkIterator<TValue>::get_startpoint()
{
    if(_is_end)
        throw;
    return _net->_edges[_curr_edge_num^1]._end;
}

template <typename TValue>
std::size_t MyFlowNetworkIterator<TValue>::get_endpoint()
{
    if(_is_end)
        throw;
    return _net->_edges[_curr_edge_num]._end;
}

template <typename TValue>
bool MyFlowNetworkIterator<TValue>::is_ended()
{
    return _is_end;
}


template <typename TValue>
void MyFlowNetworkIterator<TValue>::push_flow_r(const TValue &flow)
{
    if (!_is_end)
    {
        _net->_edges[_curr_edge_num]._flow += flow;
        _net->_edges[_curr_edge_num^1]._flow -= flow;
    }
}

template <typename TValue>
bool MyFlowNetworkIterator<TValue>::operator==(const MyFlowNetworkIterator &rhs)
{
    return (_is_end && rhs._is_end &&
            _net == rhs._net)||
           _is_end == rhs._is_end &&
           _net == rhs._net &&
           _curr_edge_num == rhs._curr_edge_num;
}

template <typename TValue>
bool MyFlowNetworkIterator<TValue>::operator!=(const MyFlowNetworkIterator &rhs)
{
    return !(*this == rhs);
}


/////////////////////////////////MyFlowNetworkIteratorOut///////////////////////////////////////////

template <typename TValue>
MyFlowNetworkIteratorOut<TValue>::MyFlowNetworkIteratorOut(MyFlowNetwork<TValue> * net, std::size_t vertex_num, bool is_end):
        MyFlowNetworkIterator<TValue>(net, vertex_num, is_end)
{
    MyFlowNetworkIterator<TValue>::_is_end |=
            (MyFlowNetworkIterator<TValue>::_curr_edge_num == MyFlowNetwork<TValue>::_INFSIZE);
};


template <typename TValue>
MyFlowNetworkIteratorOut<TValue>& MyFlowNetworkIteratorOut<TValue>::operator++()
{
    if(MyFlowNetworkIterator<TValue>::_is_end)
        return *this;
    MyFlowNetworkIterator<TValue>::_curr_edge_num =
            MyFlowNetworkIterator<TValue>::_net->_edges[MyFlowNetworkIterator<TValue>::_curr_edge_num]._prevedgeindex;
    if(MyFlowNetworkIterator<TValue>::_curr_edge_num == MyFlowNetwork<TValue>::_INFSIZE)
        MyFlowNetworkIterator<TValue>::_is_end = true;
    return *this;
}



/////////////////////////////////MyFlowNetworkIteratorIn///////////////////////////////////////////

template <typename TValue>
MyFlowNetworkIteratorIn<TValue>::MyFlowNetworkIteratorIn(MyFlowNetwork<TValue> * net, std::size_t vertex_num, bool is_end):
        MyFlowNetworkIterator<TValue>(net, vertex_num, is_end)
{
    make_xor_safe();
};

template <typename TValue>
MyFlowNetworkIteratorIn<TValue>& MyFlowNetworkIteratorIn<TValue>::operator++()
{
    if(MyFlowNetworkIterator<TValue>::_is_end)
        return *this;
    MyFlowNetworkIterator<TValue>::_curr_edge_num =
            (MyFlowNetworkIterator<TValue>::_net->_edges[MyFlowNetworkIterator<TValue>::_curr_edge_num^1]._prevedgeindex);

    make_xor_safe();
    return *this;
}


template <typename TValue>
void MyFlowNetworkIteratorIn<TValue>::make_xor_safe()
{
    if(MyFlowNetworkIterator<TValue>::_curr_edge_num == MyFlowNetwork<TValue>::_INFSIZE)
        MyFlowNetworkIterator<TValue>::_is_end = MyFlowNetworkIterator<TValue>::_is_end = true;
    else
        MyFlowNetworkIterator<TValue>::_curr_edge_num ^= 1;
}

///////////////////////MalhotraPerformer////////////////////////////////////

template<typename NetIterator>
typename NetIterator::ValueType flowsumm(NetIterator&& start, NetIterator&& end)
{
    typename NetIterator::ValueType ans = 0;
    for(;start != end; ++start)
        ans += start.get_flow();
    return ans;
}

template <typename Network>
void MalhotraPerformer<Network>::push_maxflow(Network *net)
{
    _initialize(net);
    _main_cycle();
    _deinitialize();
}

template <typename Network>
void MalhotraPerformer<Network>::_initialize(Network* net)
{
    _net = net;
    _bfs_heights.resize(_net->get_size());
    _leftpotentials.resize(_net->get_size());
    _rightpotentials.resize(_net->get_size());
    _is_deleted.resize(_net->get_size());
    _leftpotentials.resize(_net->get_size());
    _rightpotentials.resize(_net->get_size());
    _initerators.resize(_net->get_size());
    _outiterators.resize(_net->get_size());
}

template <typename Network>
void MalhotraPerformer<Network>::_main_cycle()
{
    _estimate_layers();
    while(_bfs_heights[_net->get_stock()] != -3)
    {
        _find_blokflow_in_layer();
        _estimate_layers();
    }
}

template <typename Network>
void MalhotraPerformer<Network>::_deinitialize()
{
    _net = nullptr;
    _bfs_heights.resize(0);
    _rightpotentials.resize(0);
    _leftpotentials.resize(0);
    _is_deleted.resize(0);
    _leftpotentials.resize(0);
    _rightpotentials.resize(0);
    _initerators.resize(0);
    _outiterators.resize(0);
}

template <typename Network>
void MalhotraPerformer<Network>::_find_blokflow_in_layer()
{
    _prepare_iteration();
    while(!_is_deleted[_net->get_source()] && !_is_deleted[_net->get_stock()])
    {
        std::size_t minpos = _net->get_source();
        ValueType minpush = _rightpotentials[_net->get_source()];
        for(std::size_t i = 0; i < _net->get_size(); ++i)
            if(!_is_deleted[i] && std::min(_leftpotentials[i], _rightpotentials[i]) < minpush)
            {
                minpush = std::min(_leftpotentials[i], _rightpotentials[i]);
                minpos = i;
            }
        if(minpush != 0)
        {
            if(minpos != _net->get_source())
                _push_flow_to_left(minpush, minpos);
            if(minpos != _net->get_stock())
                _push_flow_to_right(minpush, minpos);
        }
        _delete_vertex(minpos);

    }
}

template <typename Network>
void MalhotraPerformer<Network>::_prepare_iteration()
{
    _count_potential(_rightpotentials,
                     [this](size_t i){return _net->begin_out(i);},
                     [this](size_t i){return _net->end_out(i);});
    _count_potential(_leftpotentials,
                     [this](size_t i){return _net->begin_in(i);},
                     [this](size_t i){return _net->end_in(i);});
    _leftpotentials[_net->get_source()] = _rightpotentials[_net->get_source()] + 1;
    _rightpotentials[_net->get_stock()] = _leftpotentials[_net->get_stock()] + 1;
    _is_deleted.assign(_net->get_size(), false);
    for(std::size_t i = 0; i < _net->get_size(); ++i)
    {
        _initerators[i] = _net->begin_in(i);
        _outiterators[i] = _net->begin_out(i);
    }
}

template <typename Network>
void MalhotraPerformer<Network>::_delete_vertex(std::size_t vertex_num)
{
    _is_deleted[vertex_num] = true;
    for(auto it = _net->begin_out(vertex_num);  it != _net->end_out(vertex_num); ++it)
    {
        if(_is_in_lnet(it) && !_is_deleted[it.get_endpoint()])
            _leftpotentials[it.get_endpoint()] -= it.get_rem_capacity();
    }
    for(auto it = _net->begin_in(vertex_num);  it != _net->end_in(vertex_num); ++it)
    {
        if(_is_in_lnet(it) && !_is_deleted[it.get_startpoint()])
            _rightpotentials[it.get_startpoint()] -= it.get_rem_capacity();
    }
}

template <typename Network>
void MalhotraPerformer<Network>::_push_flow_to_right(ValueType val, std::size_t vertex_number)
{
    std::queue<std::size_t> que;
    std::vector<ValueType> pushe_values(_net->get_size(), 0);
    pushe_values[vertex_number] = val;
    que.push(vertex_number);
    while (!que.empty())
    {
        std::size_t current = que.front();
        ValueType descresing = pushe_values[current];
        while(descresing > 0)
        {
            if(_is_in_lnet(_outiterators[current]) && !_is_deleted[_outiterators[current].get_endpoint()])
            {

                ValueType current_push = std::min(descresing,_outiterators[current].get_rem_capacity());
                if(current_push > 0 &&
                   pushe_values[_outiterators[current].get_endpoint()] == 0 &&
                   !_is_source_or_stock(_outiterators[current].get_endpoint()))
                {
                    que.push(_outiterators[current].get_endpoint());
                }
                pushe_values[_outiterators[current].get_endpoint()] += current_push;

                _rightpotentials[current] -= current_push;
                _leftpotentials[_outiterators[current].get_endpoint()] -= current_push;

                descresing -= current_push;
                _outiterators[current].push_flow_r(current_push);
                if(_outiterators[current].get_rem_capacity() == 0)
                    ++_outiterators[current];
            }
            else {
                ++_outiterators[current];
            }
        }
        que.pop();
    }
}

template <typename Network>
void MalhotraPerformer<Network>::_push_flow_to_left(ValueType val, std::size_t vertex_number)
{
    std::queue<std::size_t> que;
    std::vector<ValueType> pushe_values(_net->get_size(), 0);
    pushe_values[vertex_number] = val;
    que.push(vertex_number);
    while (!que.empty())
    {
        std::size_t current = que.front();
        ValueType descresing = pushe_values[current];
        while(descresing > 0)
        {
            if(_is_in_lnet(_initerators[current]) && !_is_deleted[_initerators[current].get_startpoint()])
            {

                ValueType current_push = std::min(descresing,_initerators[current].get_rem_capacity());
                if(current_push > 0 &&
                   pushe_values[_initerators[current].get_startpoint()] == 0 &&
                   !_is_source_or_stock(_initerators[current].get_startpoint()))
                {
                    que.push(_initerators[current].get_startpoint());
                }
                pushe_values[_initerators[current].get_startpoint()] += current_push;

                _leftpotentials[current] -= current_push;
                _rightpotentials[_initerators[current].get_startpoint()] -= current_push;

                descresing -= current_push;
                _initerators[current].push_flow_r(current_push);
                if(_initerators[current].get_rem_capacity() == 0)
                    ++_initerators[current];
            }
            else
            {
                ++_initerators[current];
            }
        }
        que.pop();
    }
}

template <typename Network>
bool MalhotraPerformer<Network>::_is_source_or_stock(std::size_t vertex_num)
{
    return (vertex_num == _net->get_source() || vertex_num == _net->get_stock());
}


template <typename Network>
template<typename  Func1, typename Func2>
void MalhotraPerformer<Network>::_count_potential(std::vector<ValueType> &potentials, Func1 func_begin, Func2 func_end)
{
    potentials.assign(_net->get_size(), 0);
    for(std::size_t i = 0; i < _net->get_size(); ++i)
    {
        for(auto it = func_begin(i); it != func_end(i); ++it)
        {
            if(_is_in_lnet(it))
                potentials[i] += it.get_rem_capacity();
        }
    }
}

template <typename Network>
template <typename NetIterator>
bool MalhotraPerformer<Network>::_is_in_lnet(NetIterator &&it)
{
    return (_bfs_heights[it.get_startpoint()] + 1 == _bfs_heights[it.get_endpoint()]);
}

template <typename Network>
void MalhotraPerformer<Network>::_estimate_layers()
{
    _bfs_heights.assign(_net->get_size(), -3);
    _bfs_heights[_net->get_source()] = 0;
    std::queue<std::size_t> que;
    que.push(_net->get_source());
    while(!que.empty())
    {
        std::size_t current_vertex = que.front();
        for(auto it = _net->begin_out(current_vertex); it != _net->end_out(current_vertex); ++it)
        {
            if(it.get_rem_capacity() > 0 && _bfs_heights[it.get_endpoint()] == -3)
            {
                _bfs_heights[it.get_endpoint()] = _bfs_heights[current_vertex] + 1;
                que.push(it.get_endpoint());
            }
        }
        que.pop();
    }
}



//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/////////////////////Start of the task solution///////////////////////////////
//////////////////////////////////////////////////////////////////////////////

template <typename T>
struct InputLog
{
public:

    InputLog():_N(0), _topic_values(std::vector<T>(0)), _dependencies(std::vector<std::vector<T>>(0)){}

    std::size_t _N;
    std::vector<T> _topic_values;
    std::vector<std::vector<T>> _dependencies;
};

template <typename T>
InputLog<T> EnterPart(std::istream& input_stream)
{
    InputLog<T> input;
    std::size_t num_d;
    input_stream >> input._N;
    input._topic_values.resize(input._N + 1);
    for(std::size_t i = 1; i <= input._N; ++i)
    {
        input_stream >> input._topic_values[i];
    }
    input._dependencies.resize(input._N + 1);
    for(std::size_t i = 1; i <= input._N; ++i)
    {
        input_stream >> num_d;
        input._dependencies[i].resize(num_d);
        for(std::size_t j = 0; j < num_d; ++j)
        {
            input_stream >> input._dependencies[i][j];
        }
    }
    return input;
}

template <typename Network, template<typename> class Solver, typename TValue>
long long CountPart(InputLog<TValue> input)
{
    std::vector<std::vector<TValue>> solve_matrix(input._N + 2, std::vector<TValue>(input._N + 2));
    TValue ideal_var= 0;
    for(std::size_t i = 1; i <= input._N; ++i)
    {

        if(input._topic_values[i] > 0)
        {
            ideal_var += input._topic_values[i];
            solve_matrix[0][i] = input._topic_values[i];
        }
        if(input._topic_values[i] < 0)
        {
            solve_matrix[i][input._N + 1] = -input._topic_values[i];
        }
    }
    for(std::size_t i = 1; i <= input._N; ++i)
        for(std::size_t j = 0; j < input._dependencies[i].size(); ++j)
        {
            solve_matrix[i] [input._dependencies[i][j]] = 1000000000000;
        }
    Network net(input._N + 2, 0, input._N + 1, solve_matrix);
    Solver<Network> algorytm;
    algorytm.push_maxflow(&net);
    return ideal_var - flowsumm(net.begin_out(0), net.end_out(0));
}


template<typename T>
void Show(std::ostream& output_stream, T ans)
{
    output_stream << ans << std::endl;
}




template <typename Network, template<typename> class Solver, typename TValue>
void solution()
{
    InputLog<TValue> input = EnterPart<TValue>(std::cin);
    TValue ans = CountPart<Network, Solver, TValue>(input);
    Show<TValue> (std::cout, ans);

};



int main()
{
   // solution<MyFlowNetwork<long long>, MalhotraPerformer, long long>();
    size_t n, s, t, c, fir, sec;
    long long int a;
    std::vector<long long int> ans;
    std::cin >> n;
    std::cin >> c;
    std::vector<std::vector<long long>> matr(n, std::vector<long long>(n, 0));
    for (size_t i = 0; i < c; ++i) {
        std::cin >> fir >> sec >> a;
        matr[fir][sec] += a;
    }
    MyFlowNetwork<long long> flow(n, 0, n - 1, matr);
    MalhotraPerformer<MyFlowNetwork<long long>> per;
    per.push_maxflow(&flow);
    std::cout << (flowsumm(flow.begin_out(0), flow.end_out(0))) << std::endl;

    return 0;
}



Compiler output:
a.cc:80:14: error: 'numeric_limits' is not a member of 'std'
   80 |         std::numeric_limits<std::size_t>::max();
      |              ^~~~~~~~~~~~~~
a.cc:80:40: error: expected primary-expression before '>' token
   80 |         std::numeric_limits<std::size_t>::max();
      |                                        ^
a.cc:80:43: error: '::max' has not been declared; did you mean 'std::max'?
   80 |         std::numeric_limits<std::size_t>::max();
      |                                           ^~~
      |                                           std::max
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: 'std::max' declared here
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
a.cc: In constructor 'MyFlowNetwork<TValue>::MyFlowNetwork(std::size_t, std::size_t, std::size_t, const std::vector<std::vector<_Tp> >&)':
a.cc:223:57: error: 'numeric_limits' is not a member of 'std'
  223 |          _endpoints(std::vector<std::size_t>(size, std::numeric_limits<std::size_t>::max()))
      |                                                         ^~~~~~~~~~~~~~
a.cc:223:86: error: '::max' has not been declared; did you mean 'std::max'?
  223 |          _endpoints(std::vector<std::size_t>(size, std::numeric_limits<std::size_t>::max()))
      |                                                                                      ^~~
      |                                                                                      std::max
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: 'std::max' declared here
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
a.cc:223:45: error: expected primary-expression before '(' token
  223 |          _endpoints(std::vector<std::size_t>(size, std::numeric_limits<std::size_t>::max()))
      |                                             ^
a.cc:223:57: error: 'numeric_limits' is not a member of 'std'
  223 |          _endpoints(std::vector<std::size_t>(size, std::numeric_limits<std::size_t>::max()))
      |                                                         ^~~~~~~~~~~~~~
a.cc:223:83: error: expected primary-expression before '>' token
  223 |          _endpoints(std::vector<std::size_t>(size, std::numeric_limits<std::size_t>::max()))
      |                                                                                   ^
a.cc:223:86: error: '::max' has not been declared; did you mean 'std::max'?
  223 |          _endpoints(std::vector<std::size_t>(size, std::numeric_limits<std::size_t>::max()))
      |                                                                                      ^~~
      |                                                                                      std::max
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: 'std::max' declared here
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~