Language: C++

#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




using Int = long long;
//BEGIN CUT HERE
struct Fordfulkerson{
    const int INF = 1 << 28;
    struct edge{
        int to,cap,rev;
        edge(){}
        edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
    };
    
    int n;
    vector<vector<edge> > G;
    vector<int> used;
    
    Fordfulkerson(){}
    Fordfulkerson(int sz):n(sz),G(n),used(n){}
    
    pll add_edge(int from,int to,int cap){
        G[from].push_back(edge(to,cap,G[to].size()));
        // undirected
        //G[to].push_back(edge(from,cap,G[from].size()-1));
        // directed
        G[to].push_back(edge(from,cap,G[from].size()-1));
        return {from,G[from].size()-1};
    }
    
    void add_edge2(int from,int to,int cap){
        G[from].push_back(edge(to,cap,G[to].size()));
        // undirected
        //G[to].push_back(edge(from,cap,G[from].size()-1));
        // directed
        G[to].push_back(edge(from,0,G[from].size()-1));
        return {from,G[from].size()-1};
    }
    
    int dfs(int v,int t,int f){
        if(v==t) return f;
        used[v]=true;
        for(int i=0;i<(int)G[v].size();i++){
            edge &e = G[v][i];
            if(!used[e.to] && e.cap > 0 ){
                int d=dfs(e.to,t,min(f,e.cap));
                if(d>0){
                    e.cap-=d;
                    G[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }
    
    int flow(int s,int t,int lim){
        int fl=0;
        for(;;){
            fill(used.begin(),used.end(),0);
            int f=dfs(s,t,lim);
            if(f==0) return fl;
            fl+=f;
            lim-=f;
        }
    }
    
    int flow(int s,int t){
        return flow(s,t,INF);
    }
    
};
//END CUT HERE

const ll MX=10001;


int main(){
    ll v,e;
    cin>>v>>e;
    vector<pair<pll,ll>> A;
    Fordfulkerson flow(v),flow2(v);
    for(int i=0;i<e;i++){
        ll s,t,c;
        cin>>s>>t>>c;
        if(c!=1){flow.add_edge(s,t,c); flow2.add_edge(s,t,c);}
        else{A.push_back({{s,t},c});}
    }
    
    ll ans=flow.flow(0,v-1,MX);
    vector<pll> W;
    if(ans==MX){cout<<-1<<endl; return 0;}
    for(auto &I:A){W.push_back(flow.add_edge(I.F.F,I.F.S,I.S));}
    ll k=flow.flow(0,v-1,MX-ans);
    if(ans+k==MX){cout<<-1<<endl; return 0;}
    if(k==0){cout<<ans<<endl;}
    else{
        for(int i=0;i<W.size();i++){
            if(flow.G[W[i].F][W[i].S].cap==1){flow2.add_edge(A[i].F.F,A[i].F.S,A[i].S);}
            else if(flow.G[W[i].F][W[i].S].cap==0){flow2.add_edge2(A[i].F.S,A[i].F.F,2);}
            else{flow2.add_edge2(A[i].F.F,A[i].F.S,2);}
        }
        if(flow2.flow(0,v-1,MX)==ans+k){cout<<ans+k<<endl;}
        else{cout<<ans+k-1<<endl;}
    }
    
    
    return 0;
}



Compiler output:
a.cc: In member function 'void Fordfulkerson::add_edge2(int, int, int)':
a.cc:73:38: error: return-statement with a value, in function returning 'void' [-fpermissive]
   73 |         return {from,G[from].size()-1};
      |                                      ^