Problem:
Maximum Flow
A flow network is a directed graph which has a $source$ and a $sink$. In a flow network, each edge $(u, v)$ has a capacity $c(u, v)$. Each edge receives a flow, but the amount of flow on the edge can not exceed the corresponding capacity. Find the maximum flow from the $source$ to the $sink$.
Input
A flow network is given in the following format.
$|V|\;|E|$
$u_0\;v_0\;c_0$
$u_1\;v_1\;c_1$
:
$u_{|E|-1}\;v_{|E|-1}\;c_{|E|-1}$
$|V|$, $|E|$ is the number of vertices and edges of the flow network respectively. The vertices in $G$ are named with the numbers 0, 1,..., $|V|-1$. The source is 0 and the sink is $|V|-1$.
$u_i$, $v_i$, $c_i$ represent $i$-th edge of the flow network.
A pair of $u_i$ and $v_i$ denotes that there is an edge from $u_i$ to $v_i$ and $c_i$ is the capacity of $i$-th edge.
Output
Print the maximum flow.
Constraints
$2 \leq |V| \leq 100$
$1 \leq |E| \leq 1000$
$0 \leq c_i \leq 10000$
Sample Input 1
4 5
0 1 2
0 2 1
1 2 1
1 3 1
2 3 2
Sample Output 1
3

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

struct Edge {
    int to; //行き先
    int rev; //逆辺のindex
    int cap; //容量
};

struct MaxFlow {
    int N;
    vector<vector<Edge>> graph;
    vector<bool> used;

    MaxFlow(int n) : N(n), graph(n), used(n) {}

    void add_edge(int u, int v, int cap) {
        graph[u].push_back({v, (int)graph[v].size(), cap});
        graph[v].push_back({u, (int)graph[u].size()-1, 0});
    }

    int dfs(int pos, int goal, int NowFlow) {
        if (pos == goal) return NowFlow;
        used[pos] = true;
        for (auto &nex : graph[pos]) {
            if (!used[nex.to] && nex.cap > 0) {
                int d = dfs(nex.to, goal, min(NowFlow, nex.cap));
                if (d > 0) {
                    nex.cap -= d;
                    graph[nex.to][nex.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    int max_flow(int start, int goal) {
        int flow = 0;
        while (true) {
            fill(used.begin(), used.end(), false);
            int f = dfs(start, goal, INF);
            if (f == 0) break;
            flow += f;
        }
        return flow;
    }
};


int main() {
    int N, M;
    cin >> N >> M;
    MaxFlow mf(N);
    for (int i = 0; i < M; i++) {
        int u, v, c;
        cin >> u >> v >> c;
        mf.add_edge(u, v, c);
    }

    int start = 0, goal = N-1;
    int ans = mf.max_flow(start, goal);
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3492
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)

template <typename Cap>
struct FordFulkerson {
	struct edge {
		int to;
		Cap cap;
		int rev;
	};
	
	const Cap INF;
	vector<vector<edge>> G;
	vector<int> used;
	int timestamp;
	
	FordFulkerson(int N) : INF(numeric_limits<Cap>::max()), G(N), used(N, -1), timestamp(0) {}
	
	void add_edge(int from, int to, Cap cap) {
		G[from].push_back((edge){to, cap, (int)G[to].size()});
		G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
	}
	
	Cap find_path(int v, const int t, Cap flow) {
		if (v == t) return flow;
		used[v] = timestamp;
		for (auto &e : G[v]) {
			if (e.cap > 0 && used[e.to] != timestamp) {
				Cap d = find_path(e.to, t, min(flow, e.cap));
				if (d > 0) {
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}
	
	Cap max_flow(int s, int t) {
		Cap flow = 0;
		for (Cap f; (f = find_path(s, t, INF)) > 0; ++timestamp) flow += f;
		++timestamp;
		return flow;
	}
};

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	
	int N, M;
	cin >> N >> M;
	FordFulkerson<ll> ff(N);
	
	rep(i, 0, M) {
		int u, v, c;
		cin >> u >> v >> c;
		ff.add_edge(u, v, c);
	}
	cout << ff.max_flow(0, N - 1) << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 3532
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll=long long;

int dfs(vector<vector<tuple<int,int,int>>>& G,vector<bool>& checked,int cv,int cf,int goal){
    if(cv==goal) return cf;
    checked[cv]=true;

    int ca=0;
    for(auto& nv:G[cv]){
        if(checked[get<0>(nv)]||get<1>(nv)==0) continue;
        ca=dfs(G,checked,get<0>(nv),min(get<1>(nv),cf),goal);
        if(ca>0){
            get<1>(nv)-=ca;
            get<1>(G[get<0>(nv)][get<2>(nv)])+=ca;
            return ca;
        }
    }

    return 0;
}

int main(){
    int V,E; cin>>V>>E;
    vector<vector<tuple<int,int,int>>> G(V); //v, c, zansa
    for(int i=0;i<E;i++){
        int u,v,c; cin>>u>>v>>c;
        G[u].push_back({v,c,G[v].size()});
        G[v].push_back({u,0,G[u].size()-1});
    }

    int ans=0;
    while(true){
        vector<bool> checked(V,false);
        int ca=dfs(G,checked,0,1e9,V-1);
        ans+=ca;
        if(ca==0) break;
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3468
final_rank: 1

code_snippet: #include <vector>
#include <limits>
using namespace std;

//流量の型がT
template<class T>
struct MaxFlowGraph {
private:
    struct Edge {
        //to:行先
        int to;
        //cap:流量のあまり
        T cap;
        //逆辺のindex
        int rev;
    };
    vector<vector<Edge> > G;
    vector<bool> seen;
    T dfs(int v, int goal, T f) {
        //頂点tにたどり着いた
        if (v == goal) return f;
        seen[v] = true;
        for (int idx = 0; idx < (int)G[v].size(); idx++) {
            Edge& e = G[v][idx];
            if (seen[e.to]) continue;
            if (e.cap == 0) continue;
            T d = dfs(e.to, goal, min(f, e.cap));
            if (d > 0) {
                //s-tパスが見つかった
                //流量のあまりを減らす
                e.cap -= d;
                //逆辺の流量のあまりを増やす
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
        return 0;
    }
public:
    //コンストラクタ
    MaxFlowGraph() : MaxFlowGraph(0) {}
    MaxFlowGraph(int n) {
        G.resize(n);
        seen.resize(n);
    }
    //u->vの辺を追加する
    void add_edge(int u, int v, T cap) {
        G[u].push_back(Edge{v, cap, (int)G[v].size()});
        G[v].push_back(Edge{u, 0, (int)G[u].size()-1});
    }
    //s-tの最大流を求める
    T max_flow(int s, int t) {
        T ret = 0;
        while(true) {
            seen.assign((int)seen.size(), false);
            T plus = dfs(s, t, numeric_limits<T>::max());
            if (plus == 0) break;
            else ret += plus;
        }
        return ret;
    }
};

#include <iostream>

int main() {
    int V, E;
    std::cin >> V >> E;
    MaxFlowGraph<int> G(V);
    for (int i = 0; i < E; i++) {
        int u, v; std::cin >> u >> v;
        int c; std::cin >> c;
        G.add_edge(u, v, c);
    }
    std::cout << G.max_flow(0, V-1) << std::endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3472
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;

const int MAXV = 100 + 10;
const int INF = 1e9;

struct edge
{
    int to, cap, rev;
};

vector<edge> G[MAXV];
bool used[MAXV];
int n, m;

//初始化
void init()
{
    for(int i = 0; i < MAXV; i++) G[i].clear();
}

//向图中增加一条从S到T容量为CAP的边
void add_edge(int from, int to, int cap)
{
    G[from].push_back((edge){to, cap, G[to].size()});
    G[to].push_back((edge){from, 0, G[from].size()-1});
}
//通过DFS寻找增广路
int dfs(int v, int t, int f)
{
    if(v == t) return f;
    used[v] = true;
    for(int i = 0; i < 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;
}

//求解S到T的最大流
int max_flow(int s, int t)
{
    int flow = 0;
    while(1)
    {
        memset(used, 0, sizeof used);
        int f = dfs(s, t, INF);
        if(!f) return flow;
        flow += f;
    }
}

int main()
{
    int cnt = 0;
    while(~scanf("%d%d", &n, &m))
    {
        init();
        for(int i = 0; i < m; i++)
        {
            int tx, ty, cap;
            scanf("%d%d%d", &tx, &ty, &cap);
            add_edge(tx, ty, cap);
        }
        cout << max_flow(0, n - 1) << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3528
final_rank: 5

code_snippet: #line 1 "verify/graph/max_flow.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/GRL_6_A"

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

/* NAMESPACE */

using namespace std;
using namespace __gnu_pbds;

/* HASH */

struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

template<class K, class V> using safe_map = unordered_map<K, V, custom_hash>;
template<class K, class V> using safe_ht = gp_hash_table<K, V, custom_hash>;
template<class K> using safe_set = unordered_set<K, custom_hash>;
template<class K> using safe_htset = gp_hash_table<K, null_type, custom_hash>;

/* CLASSES */

using ll = long long;
using pii = pair<int, int>;
template<class T> using pp = pair<T, T>;
using pll = pp<ll>;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using greater_pq = priority_queue<T, vector<T>, greater<>>;
template<class T> using V = vector<T>;
using vi = V<int>;
using vvi = V<vi>;
using vvvi = V<vvi>;
using vll = V<ll>;

/* FUNCTIONS */

template<class T, class U>
T max(T a, U b) {
	return (a > b) ? a : b;
}

template<class T, class U>
T min(T a, U b) {
	return (a < b) ? a : b;
}

template<class T>
T power(T x, T y) {
	T res = 1;
	for (T i = 0; i < y; i++) {
		res *= x;
	}
	return res;
}

template<class T>
T nxt() {
	T x;
	cin >> x;
	return x;
}

/* MACROS */
#define clearall(arr) memset((arr), 0, sizeof (arr))
#define clearn(arr, n) memset((arr), 0, n * sizeof (arr)[0])
#define resetall(arr) memset((arr), -1, sizeof (arr))
#define resetn(arr, n) memset((arr), -1, n * sizeof (arr)[0])
#define YESNO(condition) cout << ((condition) ? "YES" : "NO")
#define sfunc(a, b, c) ((a) = c((a), (b)))
#define smin(a, b) sfunc((a), (b), min)
#define smax(a, b) sfunc((a), (b), max)
#define ALL(x) begin((x)), end((x))
#define SZ(a) (int)(a).size()
#define readall(arr, n) for (int i = 0; i < n; i++) cin >> (arr)[i]
#define printall(arr, n) for (int i = 0; i < n; i++) cout << (arr)[i] << " "
#define printalldel(arr, n, del) for (int i = 0; i < n; i++) cout << (arr)[i] << del
#define mx_val(arr) (*max_element(ALL(arr)))

/* DEBUG TEMPLATE*/
template<typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }

template<typename C, typename T = decay<decltype(*begin(
		declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type * = nullptr>
ostream &operator<<(ostream &os, const C &c) {
	bool f = true;
	os << "[";
	for (const auto &x: c) {
		if (!f) os << ", ";
		f = false;
		os << x;
	}
	return os << "]";
}

template<typename T>
void debug(string s, T x) { cerr << "\033[1;35m" << s << "\033[0;32m = \033[33m" << x << "\033[0m\n"; }

template<typename T, typename... Args>
void debug(string s, T x, Args... args) {
	for (int i = 0, b = 0; i < (int) s.size(); i++)
		if (s[i] == '(' || s[i] == '{') b++;
		else if (s[i] == ')' || s[i] == '}') b--;
		else if (s[i] == ',' && b == 0) {
			cerr << "\033[1;35m" << s.substr(0, i) << "\033[0;32m = \033[33m" << x << "\033[31m | ";
			debug(s.substr(s.find_first_not_of(' ', i + 1)), args...);
			break;
		}
}

template<typename T>
std::vector<T> vectorize(T *a, int n) {
	std::vector<T> res;
	for (int i = 0; i < n; ++i) {
		res.push_back(a[i]);
	}
	return res;
}

template<typename T, typename... Sizes>
auto vectorize(T *a, int n, Sizes... sizes) {
	std::vector<decltype(vectorize(a[0], sizes...))> res;
	for (int i = 0; i < n; ++i) {
		res.push_back(vectorize(a[i], sizes...));
	}
	return res;
}

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__)
#else
#define DEBUG(...) 42
#endif

/* CONSTANTS */
const int inf = 2e9;
const ll infl = 4e18;
const ll MOD = 998244353;
const ll MAXN = 2e5 + 5;

#line 2 "library/graph/max_flow.h"

template<typename T>
T max_flow(vector<vector<int>> &adj, vector<vector<T>> &capacity, int source, int sink) {
	int n = adj.size();
	int flow = 0;
	while (true) {
		bool found = false;
		vector<int> prev(n, -2);
		queue<int> q;

		prev[source] = -1;
		q.push(source);

		while (!q.empty()) {
			int v = q.front();
			q.pop();
			if (v == sink) {
				found = true;
				while (true) {
					int p = prev[v];
					if (p == -1) {
						break;
					}
					capacity[p][v]--;
					capacity[v][p]++;
					v = p;
				}
				flow++;
				break;
			}
			for (int u: adj[v]) {
				if (prev[u] == -2 && capacity[v][u]) {
					prev[u] = v;
					q.push(u);
				}
			}
		}
		if (!found) {
			break;
		}
	}
	return flow;
}
#line 156 "verify/graph/max_flow.test.cpp"

int solve() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> adj(n);
	vector<vector<int>> capacity(n, vector<int>(n));
	for (int i = 0; i < m; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		adj[a].push_back(b);
		adj[b].push_back(a);
		capacity[a][b] = c;
	}
	cout << max_flow(adj, capacity, 0, n - 1) << '\n';
	return 0;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T = 1;
//	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3516
final_rank: 8

code_snippet: #pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
using namespace std;
namespace io{
constexpr int N=1<<16;
using ll=long long;
template<class T>
constexpr T ten(int k){return k?ten<T>(k-1)*10:1;}
template<class T>
constexpr bool is_128=is_same_v<T,__int128>||is_same_v<T,unsigned __int128>;
struct I:istream{
char b[N],*r=b+N,*p=r;
constexpr inline void load(int need){
	if(int d=r-p;d<need){
		d=fread(copy_n(p,d,b),1,p-b,stdin);
		p=b;
	}
}
void skip(){while(*p<=' ')++p;}
void sc(char&c){
	load(5);
	skip();
	c=*p++;
}
void sc(string&s){
	s.clear();
	load(5);
	skip();
	do{
		s+=*p++;
		load(1);
	}while(*p>' ');
	++p;
}
void sc(double&x){
	string s;
	sc(s);
	x=stod(s);
}
template<class T>
enable_if_t<is_integral_v<T>&&!is_128<T>>sc(T&x){
	load(25);
	skip();
	bool neg=0;
	if(*p=='-')neg=1,++p;
	x=0;
	bool ok=0;
	while(1){
		int d=0;
		for(int i=0;i<9;i++){
			if(*p<=' '){
				ok=1;
				if(i)x=x*ten<int>(i)+d;
				++p;
				break;
			}
			d=d*10+(*p++-'0');
		}
		if(ok)break;
		x=x*ten<int>(9)+d;
	}
	if(neg)x=-x;
}
template<class T>
enable_if_t<is_128<T>>sc(T&x){
	load(45);
	skip();
	bool neg=0;
	if(*p=='-')neg=1,++p;
	x=0;
	while(1){
		uint64_t d;
		memcpy(&d,p,8);
		d-=0x3030303030303030;
		if(d&0x8080808080808080)break;
		d=(d*10+(d>>8))&0xff00ff00ff00ff;
		d=(d*100+(d>>16))&0xffff0000ffff;
		d=(d*10000+(d>>32))&0xffffffff;
		x=x*100000000+d;
		p+=8;
	}
	int d=0,c=0;
	while(*p>' '){
		d=d*10+(*p++-'0');
		++c;
	}
	++p;
	if(c)x=x*ten<int>(c)+d;
	if(neg)x=-x;
}
template<class T,class U>
void sc(pair<T,U>&x){sc(x.first),sc(x.second);}
template<int k=0,class T>
void sc_tup(T&x){
	if constexpr(k<tuple_size<T>::value){
		sc(std::get<k>(x));
		sc_tup<k+1>(x);
	}
}
template<class...T>
void sc(tuple<T...>&x){sc_tup(x);}
template<class T>
void sc(vector<T>&a){for(T&x:a)sc(x);}
template<class T>I&operator>>(T&x){sc(x);return *this;}
}_i;
struct O:ostream{
char b[N],*r=b+N,*p=b;
constexpr inline void flush(int need=N){
	if(r-p<need){
		fwrite(b,1,p-b,stdout);
		p=b;
	}
}
~O(){flush();}
void pr(char c){
	flush(1);
	*p++=c;
}
void pr(bool x){pr(x?'1':'0');}
void pr(const char*s){
	int n=strlen(s);
	for(int i=0;i<n;i++)pr(s[i]);
}
void pr(string s){for(char c:s)pr(c);}
void pr(double x){
	ostringstream os;
	os<<setprecision(18)<<x;
	pr(os.str());
}
void pr(long double x){pr((double)x);}
static constexpr auto num=[](){
	array<array<char,4>,10000>num={};
	for(int i=10000;i--;){
		int x=i;
		for(int j=4;j--;)num[i][j]=x%10|'0',x/=10;
	}
	return num;
}();
char tmp[20];
template<class T>
enable_if_t<is_integral_v<T>&&!is_128<T>>pr(T x){
	flush(20);
	if(x<0)*p++='-',x=-x;
	int i;
	for(i=20;x>=10000;){
		i-=4;
		memcpy(tmp+i,&num[x%10000][0],4);
		x/=10000;
	}
	if(x>=1000)p=copy_n(&num[x][0],4,p);
	else if(x>=100)p=copy_n(&num[x][1],3,p);
	else if(x>=10)p=copy_n(&num[x][2],2,p);
	else *p++=x|'0';
	p=copy_n(tmp+i,20-i,p);
}
template<int k=16>
void w4(ll x){
	if constexpr(k==4){
		p=copy_n(&num[x][0],4,p);
		return;
	}else{
		p=copy_n(&num[x/ten<ll>(k-4)][0],4,p);
		w4<k-4>(x%ten<ll>(k-4));
	}
}
template<class T>
enable_if_t<is_128<T>>pr(T x){
	flush(40);
	if(x<0)*p++='-',x=-x;
	if(x<ten<T>(16))pr(static_cast<ll>(x));
	else if(x<ten<T>(32)){
		pr(static_cast<ll>(x/ten<T>(16)));
		w4(static_cast<ll>(x%ten<T>(16)));
	}else{
		pr(static_cast<int>(x/ten<T>(32)));
		x%=ten<T>(32);
		w4(static_cast<ll>(x/ten<T>(16)));
		w4(static_cast<ll>(x%ten<T>(16)));
	}
}
template<class T,class U>
void pr(pair<T,U>x){pr(x.first),pr(' '),pr(x.second);}
template<int k=0,class T>
void pr_tup(T x){
	if constexpr(k<tuple_size<T>::value){
		if constexpr(k)pr(' ');
		pr(get<k>(x));
		pr_tup<k+1>(x);
	}
}
template<class...T>
void pr(tuple<T...>x){pr_tup(x);}
template<class T>
void pr(vector<T>a){
	int n=a.size();
	for(int i=0;i<n;++i){
		if(i)pr(' ');
		pr(a[i]);
	}
}
template<class T>O&operator<<(T x){pr(x);return *this;}
}_o;
void flush(){_o.flush();}
}
using io::flush;
#define cin io::_i
#define cout io::_o
int main(){
	int n,m;
	cin>>n>>m;
	auto c=vector(n,vector(n,0));
	for(int i=0;i<m;i++){
		int u,v,w;
		cin>>u>>v>>w;
		c[u][v]+=w;
	}
	vector<bool>vis(n);
	auto dfs=[&](auto dfs,int u,int in)->int{
		if(u==n-1)return in;
		if(!in||vis[u])return 0;
		vis[u]=1;
		int out=0;
		for(int v=0;v<n;v++){
			int f=dfs(dfs,v,min(c[u][v],in));
			c[u][v]-=f;
			c[v][u]+=f;
			in-=f;
			out+=f;
			if(!in)break;
		}
		return out;
	};
	int ans=0,f;
	while(f=dfs(dfs,0,1e9))ans+=f,vis.assign(n,0);
	cout<<ans<<'\n';
}
accuracy: 1
time_ms: 150
memory_kb: 3540
final_rank: 12

code_snippet: #pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
using namespace std;
namespace io{
constexpr int N=1<<16;
using ll=long long;
template<class T>
constexpr T ten(int k){return k?ten<T>(k-1)*10:1;}
template<class T>
constexpr bool is_128=is_same_v<T,__int128>||is_same_v<T,unsigned __int128>;
struct I:istream{
char b[N],*r=b+N,*p=r;
constexpr inline void load(int need){
	if(int d=r-p;d<need){
		d=fread(copy_n(p,d,b),1,p-b,stdin);
		p=b;
	}
}
void skip(){while(*p<=' ')++p;}
void sc(char&c){
	load(5);
	skip();
	c=*p++;
}
void sc(string&s){
	s.clear();
	load(5);
	skip();
	do{
		s+=*p++;
		load(1);
	}while(*p>' ');
	++p;
}
void sc(double&x){
	string s;
	sc(s);
	x=stod(s);
}
template<class T>
enable_if_t<is_integral_v<T>&&!is_128<T>>sc(T&x){
	load(25);
	skip();
	bool neg=0;
	if(*p=='-')neg=1,++p;
	x=0;
	bool ok=0;
	while(1){
		int d=0;
		for(int i=0;i<9;i++){
			if(*p<=' '){
				ok=1;
				if(i)x=x*ten<int>(i)+d;
				++p;
				break;
			}
			d=d*10+(*p++-'0');
		}
		if(ok)break;
		x=x*ten<int>(9)+d;
	}
	if(neg)x=-x;
}
template<class T>
enable_if_t<is_128<T>>sc(T&x){
	load(45);
	skip();
	bool neg=0;
	if(*p=='-')neg=1,++p;
	x=0;
	while(1){
		uint64_t d;
		memcpy(&d,p,8);
		d-=0x3030303030303030;
		if(d&0x8080808080808080)break;
		d=(d*10+(d>>8))&0xff00ff00ff00ff;
		d=(d*100+(d>>16))&0xffff0000ffff;
		d=(d*10000+(d>>32))&0xffffffff;
		x=x*100000000+d;
		p+=8;
	}
	int d=0,c=0;
	while(*p>' '){
		d=d*10+(*p++-'0');
		++c;
	}
	++p;
	if(c)x=x*ten<int>(c)+d;
	if(neg)x=-x;
}
template<class T,class U>
void sc(pair<T,U>&x){sc(x.first),sc(x.second);}
template<int k=0,class T>
void sc_tup(T&x){
	if constexpr(k<tuple_size<T>::value){
		sc(std::get<k>(x));
		sc_tup<k+1>(x);
	}
}
template<class...T>
void sc(tuple<T...>&x){sc_tup(x);}
template<class T>
void sc(vector<T>&a){for(T&x:a)sc(x);}
template<class T>I&operator>>(T&x){sc(x);return *this;}
}_i;
struct O:ostream{
char b[N],*r=b+N,*p=b;
constexpr inline void flush(int need=N){
	if(r-p<need){
		fwrite(b,1,p-b,stdout);
		p=b;
	}
}
~O(){flush();}
void pr(char c){
	flush(1);
	*p++=c;
}
void pr(bool x){pr(x?'1':'0');}
void pr(const char*s){
	int n=strlen(s);
	for(int i=0;i<n;i++)pr(s[i]);
}
void pr(string s){for(char c:s)pr(c);}
void pr(double x){
	ostringstream os;
	os<<setprecision(18)<<x;
	pr(os.str());
}
void pr(long double x){pr((double)x);}
static constexpr auto num=[](){
	array<array<char,4>,10000>num={};
	for(int i=10000;i--;){
		int x=i;
		for(int j=4;j--;)num[i][j]=x%10|'0',x/=10;
	}
	return num;
}();
char tmp[20];
template<class T>
enable_if_t<is_integral_v<T>&&!is_128<T>>pr(T x){
	flush(20);
	if(x<0)*p++='-',x=-x;
	int i;
	for(i=20;x>=10000;){
		i-=4;
		memcpy(tmp+i,&num[x%10000][0],4);
		x/=10000;
	}
	if(x>=1000)p=copy_n(&num[x][0],4,p);
	else if(x>=100)p=copy_n(&num[x][1],3,p);
	else if(x>=10)p=copy_n(&num[x][2],2,p);
	else *p++=x|'0';
	p=copy_n(tmp+i,20-i,p);
}
template<int k=16>
void w4(ll x){
	if constexpr(k==4){
		p=copy_n(&num[x][0],4,p);
		return;
	}else{
		p=copy_n(&num[x/ten<ll>(k-4)][0],4,p);
		w4<k-4>(x%ten<ll>(k-4));
	}
}
template<class T>
enable_if_t<is_128<T>>pr(T x){
	flush(40);
	if(x<0)*p++='-',x=-x;
	if(x<ten<T>(16))pr(static_cast<ll>(x));
	else if(x<ten<T>(32)){
		pr(static_cast<ll>(x/ten<T>(16)));
		w4(static_cast<ll>(x%ten<T>(16)));
	}else{
		pr(static_cast<int>(x/ten<T>(32)));
		x%=ten<T>(32);
		w4(static_cast<ll>(x/ten<T>(16)));
		w4(static_cast<ll>(x%ten<T>(16)));
	}
}
template<class T,class U>
void pr(pair<T,U>x){pr(x.first),pr(' '),pr(x.second);}
template<int k=0,class T>
void pr_tup(T x){
	if constexpr(k<tuple_size<T>::value){
		if constexpr(k)pr(' ');
		pr(get<k>(x));
		pr_tup<k+1>(x);
	}
}
template<class...T>
void pr(tuple<T...>x){pr_tup(x);}
template<class T>
void pr(vector<T>a){
	int n=a.size();
	for(int i=0;i<n;++i){
		if(i)pr(' ');
		pr(a[i]);
	}
}
template<class T>O&operator<<(T x){pr(x);return *this;}
}_o;
void flush(){_o.flush();}
}
using io::flush;
#define cin io::_i
#define cout io::_o
int main(){
	int n,m;
	cin>>n>>m;
	auto c=vector(n,vector(n,0));
	for(int i=0;i<m;i++){
		int u,v,w;
		cin>>u>>v>>w;
		c[u][v]+=w;
	}
	vector<bool>vis(n);
	auto dfs=[&](auto dfs,int u,int in)->int{
		if(!in)return 0;
		if(u==n-1)return in;
		if(vis[u])return 0;
		vis[u]=1;
		for(int v=0;v<n;v++){
			int f=dfs(dfs,v,min(c[u][v],in));
			if(f){
				c[u][v]-=f;
				c[v][u]+=f;
				return f;
			}
		}
		return 0;
	};
	int ans=0;
	bool upd=1;
	while(upd){
		upd=0;
		vis.assign(n,0);
		int f;
		while(f=dfs(dfs,0,1e9))ans+=f,upd=1;
	}
	cout<<ans<<'\n';
}
accuracy: 1
time_ms: 160
memory_kb: 3540
final_rank: 14

code_snippet: #pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
using namespace std;
namespace io{
constexpr int N=1<<16;
using ll=long long;
template<class T>
constexpr T ten(int k){return k?ten<T>(k-1)*10:1;}
template<class T>
constexpr bool is_128=is_same_v<T,__int128>||is_same_v<T,unsigned __int128>;
struct I:istream{
char b[N],*r=b+N,*p=r;
constexpr inline void load(int need){
	if(int d=r-p;d<need){
		d=fread(copy_n(p,d,b),1,p-b,stdin);
		p=b;
	}
}
void skip(){while(*p<=' ')++p;}
void sc(char&c){
	load(5);
	skip();
	c=*p++;
}
void sc(string&s){
	s.clear();
	load(5);
	skip();
	do{
		s+=*p++;
		load(1);
	}while(*p>' ');
	++p;
}
void sc(double&x){
	string s;
	sc(s);
	x=stod(s);
}
template<class T>
enable_if_t<is_integral_v<T>&&!is_128<T>>sc(T&x){
	load(25);
	skip();
	bool neg=0;
	if(*p=='-')neg=1,++p;
	x=0;
	bool ok=0;
	while(1){
		int d=0;
		for(int i=0;i<9;i++){
			if(*p<=' '){
				ok=1;
				if(i)x=x*ten<int>(i)+d;
				++p;
				break;
			}
			d=d*10+(*p++-'0');
		}
		if(ok)break;
		x=x*ten<int>(9)+d;
	}
	if(neg)x=-x;
}
template<class T>
enable_if_t<is_128<T>>sc(T&x){
	load(45);
	skip();
	bool neg=0;
	if(*p=='-')neg=1,++p;
	x=0;
	while(1){
		uint64_t d;
		memcpy(&d,p,8);
		d-=0x3030303030303030;
		if(d&0x8080808080808080)break;
		d=(d*10+(d>>8))&0xff00ff00ff00ff;
		d=(d*100+(d>>16))&0xffff0000ffff;
		d=(d*10000+(d>>32))&0xffffffff;
		x=x*100000000+d;
		p+=8;
	}
	int d=0,c=0;
	while(*p>' '){
		d=d*10+(*p++-'0');
		++c;
	}
	++p;
	if(c)x=x*ten<int>(c)+d;
	if(neg)x=-x;
}
template<class T,class U>
void sc(pair<T,U>&x){sc(x.first),sc(x.second);}
template<int k=0,class T>
void sc_tup(T&x){
	if constexpr(k<tuple_size<T>::value){
		sc(std::get<k>(x));
		sc_tup<k+1>(x);
	}
}
template<class...T>
void sc(tuple<T...>&x){sc_tup(x);}
template<class T>
void sc(vector<T>&a){for(T&x:a)sc(x);}
template<class T>I&operator>>(T&x){sc(x);return *this;}
}_i;
struct O:ostream{
char b[N],*r=b+N,*p=b;
constexpr inline void flush(int need=N){
	if(r-p<need){
		fwrite(b,1,p-b,stdout);
		p=b;
	}
}
~O(){flush();}
void pr(char c){
	flush(1);
	*p++=c;
}
void pr(bool x){pr(x?'1':'0');}
void pr(const char*s){
	int n=strlen(s);
	for(int i=0;i<n;i++)pr(s[i]);
}
void pr(string s){for(char c:s)pr(c);}
void pr(double x){
	ostringstream os;
	os<<setprecision(18)<<x;
	pr(os.str());
}
void pr(long double x){pr((double)x);}
static constexpr auto num=[](){
	array<array<char,4>,10000>num={};
	for(int i=10000;i--;){
		int x=i;
		for(int j=4;j--;)num[i][j]=x%10|'0',x/=10;
	}
	return num;
}();
char tmp[20];
template<class T>
enable_if_t<is_integral_v<T>&&!is_128<T>>pr(T x){
	flush(20);
	if(x<0)*p++='-',x=-x;
	int i;
	for(i=20;x>=10000;){
		i-=4;
		memcpy(tmp+i,&num[x%10000][0],4);
		x/=10000;
	}
	if(x>=1000)p=copy_n(&num[x][0],4,p);
	else if(x>=100)p=copy_n(&num[x][1],3,p);
	else if(x>=10)p=copy_n(&num[x][2],2,p);
	else *p++=x|'0';
	p=copy_n(tmp+i,20-i,p);
}
template<int k=16>
void w4(ll x){
	if constexpr(k==4){
		p=copy_n(&num[x][0],4,p);
		return;
	}else{
		p=copy_n(&num[x/ten<ll>(k-4)][0],4,p);
		w4<k-4>(x%ten<ll>(k-4));
	}
}
template<class T>
enable_if_t<is_128<T>>pr(T x){
	flush(40);
	if(x<0)*p++='-',x=-x;
	if(x<ten<T>(16))pr(static_cast<ll>(x));
	else if(x<ten<T>(32)){
		pr(static_cast<ll>(x/ten<T>(16)));
		w4(static_cast<ll>(x%ten<T>(16)));
	}else{
		pr(static_cast<int>(x/ten<T>(32)));
		x%=ten<T>(32);
		w4(static_cast<ll>(x/ten<T>(16)));
		w4(static_cast<ll>(x%ten<T>(16)));
	}
}
template<class T,class U>
void pr(pair<T,U>x){pr(x.first),pr(' '),pr(x.second);}
template<int k=0,class T>
void pr_tup(T x){
	if constexpr(k<tuple_size<T>::value){
		if constexpr(k)pr(' ');
		pr(get<k>(x));
		pr_tup<k+1>(x);
	}
}
template<class...T>
void pr(tuple<T...>x){pr_tup(x);}
template<class T>
void pr(vector<T>a){
	int n=a.size();
	for(int i=0;i<n;++i){
		if(i)pr(' ');
		pr(a[i]);
	}
}
template<class T>O&operator<<(T x){pr(x);return *this;}
}_o;
void flush(){_o.flush();}
}
using io::flush;
#define cin io::_i
#define cout io::_o
int main(){
	int n,m;
	cin>>n>>m;
	auto c=vector(n,vector(n,0));
	for(int i=0;i<m;i++){
		int u,v,w;
		cin>>u>>v>>w;
		c[u][v]+=w;
	}
	vector<bool>vis(n);
	auto dfs=[&](auto dfs,int u)->bool{
		if(u==n-1)return 1;
		if(vis[u])return 0;
		vis[u]=1;
		for(int v=0;v<n;v++)if(c[u][v]&&dfs(dfs,v)){
			c[u][v]--;
			c[v][u]++;
			return 1;
		}
		return 0;
	};
	int ans=0;
	bool upd=1;
	while(upd){
		upd=0;
		vis.assign(n,0);
		while(dfs(dfs,0))ans++,upd=1;
	}
	cout<<ans<<'\n';
}
accuracy: 1
time_ms: 220
memory_kb: 3524
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
using vb=vector<bool>;
#define rep(i,s,e) for(int i=s;i<e;i++)
#define in(v,seq) for(auto v:seq)
#define print(s) cout << s << endl;
const int I_INF=1<<30;

struct Edge{
  int to; // 行先
  int rem; // 残余
  int rev; // 逆辺のindex
  Edge(int t,int rm,int rv):to(t),rem(rm),rev(rv){}
};
using Graph=vector<vector<Edge>>;

int vertex,edge;
Graph G;
vb seen;

// v:現在の頂点 t:ゴール f:そのパスに流せる水量
int dfs(int v,int t,int f){
  if(v==t) return f; // ゴールしたら一気にreturn開始

  seen[v]=true;
  in(&e,G[v]){
    if(seen[e.to] || e.rem==0) continue;

    int res=dfs(e.to,t,min(f,e.rem));
    if(res<=0) continue;
    e.rem-=res;
    G[e.to][e.rev].rem+=res;
    return res;
  }

  return 0; // パスが存在しない
}

int main(){
  cin >> vertex >> edge;
  G.resize(vertex);
  rep(i,0,edge){
    int s,e,r; cin >> s >> e >> r;
    G[s].emplace_back(e,r,G[e].size()); //sizeが逆辺のindexになることに注意
    G[e].emplace_back(s,0,G[s].size()-1); // 逆辺 "-1"が必要なことに注意
  }

  int ans=0;
  while(true){
    seen.assign(vertex,false);
    int flow=dfs(0,vertex-1,I_INF);
    if(flow==0) break; // パスがなかったら終わり
    ans+=flow;
  }

  print(ans);
}
accuracy: 1
time_ms: 20
memory_kb: 3584
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

int dfs(int s, int t, int flow_amount, vector<vector<int>>& capacity, vector<bool>& used) {
    if (s == t) return flow_amount;
    used[s] = true;

    for (int i = 0; i < capacity.size(); i++) {
        if (capacity[s][i] > 0 && !used[i]) {
            int possible_flow = dfs(i, t, min(flow_amount, capacity[s][i]), capacity, used);
            if (possible_flow > 0) {
                capacity[s][i] -= possible_flow;
                capacity[i][s] += possible_flow;
                return possible_flow;
            }
        }
    }
    return 0;
}


int main() {
    int v, e;
    cin >> v >> e;
    vector<vector<int>> capacity(v, vector<int>(v,0));
    for (int i = 0; i < e; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        capacity[a][b] = c;
    }

    int source = 0;
    int sink = v-1;
    int max_flow = 0;

    while (true) {
        vector<bool> used(v,false);
        int f = dfs(source, sink, INT_MAX, capacity, used);
        if (f == 0) break;
        max_flow += f;
    }

    cout << max_flow << endl;
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3488
final_rank: 7

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define all(v) v.begin(),v.end()
#define resort(v) sort(v.rbegin(),v.rend())
using ll = long long;
using ull = unsigned long long;
using vll=vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,ll>;
using vp=vector<pair<ll, ll>>;
using djks=priority_queue<P, vp, greater<P>>;

const ll inf=1ll<<60;
#define mod10 (ll)1e9+7
#define mod99 (ll)998244353
const double PI = acos(-1);

#define rep(i,n) for (ll i=0;i<n;++i)
#define per(i,n) for(ll i=n-1;i>=0;--i)
#define rep2(i,a,n) for (ll i=a;i<n;++i)
#define per2(i,a,n) for (ll i=n-1;i>=a;--i)


template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

ll dx[] = {1, 0, -1, 0, -1, 1, -1, 1};
ll dy[] = {0, 1, 0, -1, -1, 1, 1, -1};

void solve() {
    int n, m; cin >> n >> m;
    vvll g(n, vll(n, 0)); // g_i,j := 頂点iから頂点jへ向かう容量の最大
    int u, v, w;
    rep(_,m){
        cin >> u >> v >> w;
        g[u][v] += w;
    }

    ll sum = 0;
    rep(i,n) sum+=g[0][i];

    vector<pair<int, int>> tracking;
    vector<bool> seen(n, false);
    while(true) {
        stack<pair<int, int>> stk;
        
        // dfs
        stk.push({0, 1<<30});
        
        while(!stk.empty() && !seen[n-1]) {
            auto [p, flow] = stk.top(); stk.pop();

            if(p<0||p>=n) {
                // 帰りがけ
                assert(!tracking.empty());
                tracking.pop_back();
            } else {
                if(seen[p]) { continue; }
                seen[p] = true;
    
                // 行きがけ
                tracking.push_back({p, flow});
                stk.push({~p, 0});

                rep(i, n) {
                    if(g[p][i] > 0 && !seen[i]) {
                        stk.push({ i, g[p][i] });
                    }
                }
            }
        }

        if(tracking.empty()) break; // 路が存在しない

        int flow = 1<<30;
        for(auto[_, s]: tracking) {
            chmin(flow, s);
        }
        
        rep(i, tracking.size()-1) {
            auto [from, _] = tracking[i];
            auto [to, __] = tracking[i+1];

            g[from][to] -= flow;
            g[to][from] += flow;

            assert(g[from][to] >= 0);
        }
        tracking.clear();
        fill(all(seen), false);
    }

    ll d = 0;
    rep(i,n) d += g[0][i];
    cout << sum - d << '\n';
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t=1;
    //cin >> t;
    while(t--)solve();
}
accuracy: 1
time_ms: 20
memory_kb: 3552
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
struct maxflow{
	int n;
	vector<vector<int>>c;
	vector<bool>vis;
	maxflow(int n):n(n),c(n,vector<int>(n)){}
	void add_edge(int u,int v,int w){c[u][v]+=w;}
	bool dfs(int u,int t){
		if(u==t)return 1;
		if(vis[u])return 0;vis[u]=1;
		for(int v=0;v<n;v++)if(c[u][v]&&dfs(v,t)){c[u][v]--,c[v][u]++;return 1;}
		return 0;
	}
	int flow(int s,int t){int f=0;while(vis.assign(n,0),dfs(s,t))f++;return f;}
};
int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	int n,m;
	cin>>n>>m;
	maxflow mf(n);
	while(m--){
		int u,v,w;
		cin>>u>>v>>w;
		mf.add_edge(u,v,w);
	}
	cout<<mf.flow(0,n-1)<<'\n';
}
accuracy: 1
time_ms: 190
memory_kb: 3500
final_rank: 13

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using ld = long double;
#define m_p make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define grep(i, k, n) for(ll i=(ll)(k); i<(ll)(n); i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend() //降順
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//using mint = modint998244353;
//using mint = modint1000000007;

class MaxFlow{
private:
    constexpr static long long int LINF = 2e18;
    int V, E;
    struct edge {int to; long long int cap; int rev;};
    vector<vector<edge>> g;
    vector<bool> vis;

public:
    MaxFlow(int V_, int E_) : V(V_), E(E_), g(V_), vis(V_, false) {};

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

private:
    long long int dfs(int u, int t, long long int f){
        if(u == t) return f;
        vis[u] = true;
        for(int i=0; i<g[u].size(); i++){
            edge e = g[u][i];
            if(!vis[e.to] && e.cap>0){
                long long int d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    g[u][i].cap -= d;
                    g[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

public:
    long long int max_flow(int s, int t){
        int flow = 0;
        while(true){
            vis.assign(V, false);
            long long int f = dfs(s, t, LINF);
            if(f == 0) return flow;
            flow += f;
        }
    }
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int v,e;cin>>v>>e;
    MaxFlow mf(v, e);
    rep(i,e){
        int u,v;ll c;cin>>u>>v>>c;
        mf.add_edge(u,v,c);
    }
    cout<<mf.max_flow(0,v-1)<<endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3516
final_rank: 4

code_snippet: #include <iostream>
#include <stack>
using namespace std;

int main()
{
    int V, E;
    cin >> V >> E;

    int G[100][100] = {{0}};

    for(int i=0; i<E; i++){
        int u, v, c;
        cin >> u >> v >> c;
        G[u][v] = c;
    }

    int F = 0;

    while(true){
        stack<int> S;
        int d[100] = {0};
        S.push(0);
        d[0] = 1;

        while(!S.empty()){
            int u = S.top();
            int v = -1;

            for(int j=0; j<V; j++){
                if(G[u][j]>0 && d[j]==0){
                    v = j;
                    break;
                }
            }
            if(v!=-1){
                S.push(v);
                d[v] = 1;
            }
            else{
                S.pop();
            }
            if(v==V-1){
                break;
            }
        }
        if(S.empty()){
            cout << F << endl;
            return 0;
        }
        F++;

        int s, t;
        s = S.top();
        S.pop();

        while(!S.empty()){
            t = s;
            s = S.top();
            S.pop();
            
            G[s][t]--;
            G[t][s]++;
        }
    }
}
accuracy: 1
time_ms: 250
memory_kb: 3484
final_rank: 18

code_snippet: #if __has_include(<atcoder/all>)
#include<atcoder/all>
using namespace atcoder;
using mint=modint998244353;
using mint1=modint1000000007;
#endif
#if __has_include(<ext/pb_ds/assoc_container.hpp>) && __has_include(<ext/pb_ds/tree_policy.hpp>)
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class s,class t>using __gnu_map=tree<s,t,std::less
,rb_tree_tag,tree_order_statistics_node_update>;
template<class s,class t>struct gnu_map:public __gnu_map<s,t>{
	using iterator=typename __gnu_map<s,t>::iterator;
	iterator get(int64_t idx){return this->find_by_order(idx<0?this->size()-idx:idx);}
	size_t ord(const s&key){return this->order_of_key(key);}
};
template<class s>struct gnu_set:public gnu_map<s,null_type>{gnu_map<s,null_type>::iterator operator[](int64_t i){return this->get(i);}};
#endif
#include <bits/stdc++.h>
using namespace std;
using std::cin;
using std::cout;
using sstream=stringstream;
#define RET return
#define int long long
#define itn long long
#define fi first
#define se second
#define endl '\n'
#define sn(i,c) " \n"[i==c];
#define rsv(n) reserve(n)
#define pf(a) push_front(a)
#define pb(a) push_back(a)
#define eb(...) emplace_back(__VA_ARGS__)
#define ppf() pop_front()
#define ppb() pop_back()
#define pp() pop()
#define ins(a) insert(a)
#define emp(...) emplace(__VA_ARGS__)
#define ers(a) erase(a)
#define cont(a) contains(a)
#define mp(f,s) make_pair(f,s)
#define A(a) begin(a),end(a)
#define I(a,i) begin(a),begin(a)+(i)
#define elif(c) else if(c)
#define _SEL4(_1,_2,_3,_4,name,...) name
#define _SEL3(_1,_2,_3,name,...) name
#define _REP4(i,s,n,st) for(int i=(s);i<(n);i+=(st))
#define _REP3(i,s,n) _REP4(i,s,n,1)
#define _REP2(i,n) _REP3(i,0,n)
#define _REP1(n) _REP2(_,n)
#define _RREP4(i,n,t,s) for(int i=(n);i>=(t);i-=(s))
#define _RREP3(i,n,t) _RREP4(i,n,t,1)
#define _RREP2(i,n) _RREP3(i,n,0)
#define _ITER2(x,a) for(auto&x:a)
#define _ITER3(x,y,a) for(auto&[x,y]:a)
#define _CTER2(x,a) for(const auto&x:a)
#define _CTER3(x,y,a) for(const auto&[x,y]:a)
#define rep(...) _SEL4(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define rrep(...) _SEL4(__VA_ARGS__,_RREP4,_RREP3,_RREP2,_REP1)(__VA_ARGS__)
#define forif(c,...) rep(__VA_ARGS__)if(c)
#define iter(...) _SEL3(__VA_ARGS__,_ITER3,_ITER2)(__VA_ARGS__)
#define cter(...) _SEL3(__VA_ARGS__,_CTER3,_CTER2)(__VA_ARGS__)
#define _LB_BEX(b,e,x) lower_bound(b,e,x)
#define _LB_BEXG(b,e,x,g) lower_bound(b,e,x,g)
#define _UB_BEX(b,e,x) upper_bound(b,e,x)
#define _UB_BEXG(b,e,x,g) upper_bound(b,e,x,g)
#define lb(...) _SEL4(__VA_ARGS__,_LB_BEXG,_LB_BEX)(__VA_ARGS__)
#define ub(...) _SEL4(__VA_ARGS__,_UB_BEXG,_UB_BEX)(__VA_ARGS__)
#define rev(a) reverse(A(a))
#define minel(a) min_element(A(a))
#define maxel(a) max_element(A(a))
#define acm(a) accumulate(A(a),0ll)
#define nxpm(a) next_permutation(A(a))
#define Sort(a) sort(A(a))
#define uni(a) Sort(a);a.erase(unique(A(a)),a.end())
#define swapcase(a) a=(isalpha(a)?a^32:a)
#define NL cout<<'\n'
template<class f>using gr=greater<f>;
template<class f>using vc=vector<f>;
template<class f>using vv=vc<vc<f>>;
template<class f>using v3=vv<vc<f>>;
template<class f>using v4=vv<vv<f>>;
template<class f>using pq=priority_queue<f>;
template<class f>using pqg=priority_queue<f, vc<f>, gr<f>>;
#define uset unordered_set
#define umap unordered_map
using i8=int8_t; using i16=int16_t; using i32=int32_t; using i64=int64_t; using i128=__int128_t;
using u8=uint8_t;using u16=uint16_t;using u32=uint32_t;using u64=uint64_t;using u128=__uint128_t;
using intw=__int128_t;using uintw=__uint128_t; using it=i32;
using f32=float;using f64=double;using f128=long double;
using vi=vc<int>;using vb=vc<bool>;
using pi=pair<int,int>;
using str=string;using vs=vc<str>;
using pqgp=pqg<pi>;
#define double f128
constexpr int inf=1ll<<60,minf=-inf;
constexpr char sep='\n';
constexpr array<pi,8>dc={{{1,0},{0,1},{-1,0},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}}};
template<class T,class U>inline void chmax(T&a,const U&b){if(a<b)a=b;}
template<class T,class U>inline void chmin(T&a,const U&b){if(a>b)a=b;}
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define yn(c) (c)?yes:no
#if __cplusplus <= 202002L
#else
#define C const
namespace vies=std::views;
#define DR(i) views::drop(i)
#define TK(i) views::take(i)
#define RV views::reverse
#define IOTA vies::iota
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) str __VA_ARGS__;in(__VA_ARGS__)
#define VI(a,n) vi a(n);in(a)
#define VS(a,n) vs a(n);in(a)
#define UV(u,v) INT(u,v);u--,v--
#define UVW(u,v,w) INT(u,v,w);u--,v--
template<integral T,integral U>inline auto ceil(C T a,C U b){return(a+b-1)/b;}
template<integral T,integral U>inline auto floor(C T a,C U b){return a/b-(a%b&&(a^b)<0);}
template<class T,class U>concept LUBI= same_as<T,vc<U>>||same_as<T,deque<U>>||is_array_v<T>;
#define TP template<class T,class U,typename cp=less<U>>
#define RL requires LUBI<T,U>
TP u64 lbi(C T&v,C U&x,cp cmp=cp())RL{RET lb(A(v),x,cmp)-begin(v);}
TP u64 ubi(C T&v,C U&x,cp cmp=cp())RL{RET ub(A(v),x,cmp)-begin(v);}
TP u64 lbi(u64 i,C T&v,C U&x,cp cmp=cp())RL{RET lb(i+A(v),x,cmp)-begin(v);}
TP u64 ubi(u64 i,C T&v,C U&x,cp cmp=cp())RL{RET ub(i+A(v),x,cmp)-begin(v);}
TP u64 lbi(C T&v,u64 i,C U&x,cp cmp=cp())RL{RET lb(I(v,i),x,cmp)-begin(v);}
TP u64 ubi(C T&v,u64 i,C U&x,cp cmp=cp())RL{RET ub(I(v,i),x,cmp)-begin(v);}
TP u64 lbi(u64 i,C T&v,u64 e,C U&x,cp cmp=cp())RL{RET lb(i+I(v,e),x,cmp)-begin(v);}
TP u64 ubi(u64 i,C T&v,u64 e,C U&x,cp cmp=cp())RL{RET ub(i+I(v,e),x,cmp)-begin(v);}
#undef TP
#undef RL
#define TP template
TP<class T>concept Lint=is_integral_v<T>&&sizeof(T)>8;
TP<Lint T>ostream&operator<<(ostream&dst,T val){
	ostream::sentry s(dst);
	if(!s)return dst;
	char _O128[64];
	char*d=end(_O128);
	bool vsign=val<0;
	uintw v=val;
	if(vsign&&val!=numeric_limits<T>::min())v=1+~(uintw)val;
	do{
		*(--d)="0123456789"[v%10];
		v/=10;
	}while(v!=0);
	if(vsign)*(--d)='-';
	size_t len=end(_O128)-d;
	if(dst.rdbuf()->sputn(d,len)!=len)dst.setstate(ios_base::badbit);
	return dst;
}
TP<Lint T>istream&operator>>(istream&src,T&val) {
	str s;src>>s;
	bool is_neg=numeric_limits<T>::is_signed&&s.size()>0&&s[0]=='-';
	for(val=0;C auto&x:s|views::drop(is_neg))val=10*val+x-'0';
	if(is_neg)val*=-1;
	return src;
}
#define MUT make_unsigned_t
TP<integral T>i32 pcnt(T p){return popcount(MUT<T>(p));}
TP<integral T>i32 lsb(T p){return countl_zero(MUT<T>(p));}
TP<integral T>i32 msb(T p){return countr_zero(MUT<T>(p));}
TP<i32 N,integral T>void putbit(T s){
	char buf[N+1]={0};
	for(char*itr=buf+N-1;itr>=buf;itr--,s>>=1)
		*itr='0'+(s&1);
	cout<<buf<<sep;
}
TP<class T>concept Itrabl=requires(C T&x){x.begin();x.end();}&&!std::is_same_v<T,string>;
TP<class T>concept IItrabl=Itrabl<T>&&Itrabl<typename T::value_type>;
TP<class T>concept ModInt=requires(C T&x){x.val();};
TP<class T>concept NLobj=Itrabl<T>||std::is_same_v<T,string>;
TP<ModInt T>istream&operator>>(istream&is,T&v){int x;is>>x;v=x;return is;}
TP<Itrabl T>istream&operator>>(istream&is,T&v){iter(x,v)is>>x;return is;}
TP<class T,class U>istream&operator>>(istream&is,pair<T,U>&v){return is>>v.first>>v.second;}
TP<class T>void in(T&a){cin>>a;}
TP<class T,class... Ts>void in(T&a,Ts&... b){in(a);in(b...);}
TP<class T,class U>vc<pair<T,U>>zip(size_t n,size_t m){
	vc<pair<T,U>>r(min(n,m));
	iter(x,y,r)in(x);
	iter(x,y,r)in(y);
	return move(r);
}
TP<class T,class U>vc<pair<T,U>>zip(size_t n){return move(zip<T,U>(n,n));}
TP<ModInt T>ostream&operator<<(ostream&os,const T&v){return os<<v.val(); }
TP<Itrabl T>ostream&operator<<(ostream&os,const T&v){int cnt=0;cter(x,v)os<<x<<(++cnt<v.size()?" ":"");return os;}
TP<IItrabl T>ostream&operator<<(ostream&os,const T&v){int cnt=0;cter(x,v)os<<x<<(++cnt<v.size()?"\n":"");return os;}
TP<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>&v){return os<<'('<<v.first<<','<<v.second<<')';}
ostream*dos=&cout;
int32_t OFLG; // 0:first, 1:notNLobj, 2:NLobj
TP<class T>void _out(const T&a){if(OFLG)(*dos)<<"0 \n"[OFLG]<<a;else(*dos)<<a;OFLG=1;}
TP<NLobj T>void _out(const T&a){(*dos)<<(OFLG?"\n":"")<<a;OFLG=2;}
TP<class T,class...Ts>void _out(const T&a,const Ts&... b){_out(a);_out(b...);}
TP<class... Ts>void out(const Ts&... v){OFLG=0;_out(v...);(*dos)<<sep;}
#undef TP
#undef C
#endif
#ifdef LOCAL
#define dput(...) dos=&cerr;putv(__VA_ARGS__);dos=&cout
#else
#define dput(...)
#endif

#undef rev

template<class type>
class max_flow{
	class edge {
		public:
			edge(int64_t u, type c, int64_t r):to(u),cap(c),rev(r) {}
			int64_t to, rev;
			type cap;
	};
	vector<vector<edge>>e;
	vector<bool>seen;
	int64_t g,r;
	int64_t dfs(int64_t now,type ret){
		if(now==g)return ret;
		seen[now]=true;
		for(auto&x:e[now]){
			if(x.cap==0||seen[x.to])continue;
			int64_t p=dfs(x.to,min(x.cap,ret));
			if(p){
				x.cap-=p;
				e[x.to][x.rev].cap+=p;
				return p;
			}
		}
		return 0;
	}
	public:
		max_flow(int64_t n){ e.resize(n), seen.resize(n); }
		void add(int64_t u,int64_t v,type c){
			int64_t ru=e[u].size(),rv=e[v].size();
			e[u].pb(edge(v,c,rv)), e[v].pb(edge(u,static_cast<type>(0),ru));
		}
		int64_t flow(int64_t s,int64_t t){
			g=t,r=0;
			while(1){
				fill(A(seen),false);
				int64_t p=dfs(s,1ll<<62);
				if(p)r+=p;
				else break;
			}
			return r;
		}
};
void slv(){
	INT(n,m);
	::max_flow<int>mf(n);
	rep(m){
		INT(a,b,c);
		mf.add(a,b,c);
	}
	out(mf.flow(0,n-1));
}

signed main(){
	cin.tie(0)->sync_with_stdio(0);
	cout<<fixed<<setprecision(15);
	slv();
}
accuracy: 1
time_ms: 20
memory_kb: 3712
final_rank: 17

code_snippet: #include <iostream>
#include <unordered_map>
#include <utility>
#include <vector>
#include <algorithm>
#include <climits>

class MaximumFlow{
    std::unordered_map<int, std::unordered_map<int,int>> mFlowNetwork;
    int mSource;
    int mSink;

    std::unordered_map<int, std::unordered_map<int,int>> mResidualNetwork;
    std::vector<int> mAugmentationPath;
    int mAddedFlow;

    std::unordered_map<int, std::unordered_map<int,int>> mFlow;
    int mFlowValue;

    void updateFlowNetwork(){
        int from = mSource;
        for (int to : mAugmentationPath){
            mResidualNetwork.at(from).at(to) -= mAddedFlow;
            mResidualNetwork.at(to).at(from) += mAddedFlow;

            from = to;
        }
    }

    bool dfs(int currentVertex, std::unordered_map<int,bool>& isVisited, int currentMaxCapacity){
        auto iter = mResidualNetwork.at(currentVertex).find(mSink);
        if (iter != mResidualNetwork.at(currentVertex).end() && (*iter).second > 0){
            mAugmentationPath.push_back(mSink);
            mAddedFlow = std::min(currentMaxCapacity, (*iter).second);
            return true;
        }

        for (std::pair<int,int> edge : mResidualNetwork.at(currentVertex)){
            int to = edge.first;
            int capacity = edge.second;

            if (!isVisited.at(to) && capacity > 0){
                isVisited.at(to) = true;
                mAugmentationPath.push_back(to);
                if (dfs(to, isVisited, std::min(currentMaxCapacity, capacity))){
                    return true;
                } else {
                    mAugmentationPath.pop_back();
                }
            }
        }

        return false;
    }

    bool FindAugmentationPath(){
        mAugmentationPath.clear();
        mAddedFlow = 0;

        std::unordered_map<int,bool> isVisited;
        for (const std::pair<int,std::unordered_map<int,int>>& edge : mResidualNetwork){
            isVisited[edge.first] = false;
        }

        isVisited.at(mSource) = true;
        return dfs(mSource, isVisited, INT_MAX);
    }

    void calcFlow(){
        for (std::pair<int, std::unordered_map<int,int>> edgeSet : mFlowNetwork){
            int from = edgeSet.first;
            mFlow[from] = std::unordered_map<int,int>();
            for (std::pair<int,int> edge : edgeSet.second){
                int to = edge.first;
                mFlow.at(from)[to] = mFlowNetwork.at(from).at(to) - mResidualNetwork.at(from).at(to);
            }
        }

        mFlowValue = 0;
        for (std::pair<int,int> edge : mFlow.at(mSource)){
            mFlowValue += edge.second;
        }
    }

public:
    MaximumFlow(std::unordered_map<int, std::unordered_map<int,int>> flowNetwork, int source, int sink)
     : mFlowNetwork(flowNetwork), mSource(source), mSink(sink), mResidualNetwork(flowNetwork) {
        for (std::pair<int, std::unordered_map<int,int>> edgeSet : mFlowNetwork){
            int from = edgeSet.first;
            for (std::pair<int,int> edge : edgeSet.second){
                int to = edge.first;
                mResidualNetwork.at(to)[from] = 0;
            }
        }
        mAugmentationPath.clear();
        mAddedFlow = 0;
    }

    void FordFulkerson(){
        bool existsAugmentationPath = true;

        while (existsAugmentationPath){
            updateFlowNetwork();
            existsAugmentationPath = FindAugmentationPath();
        }

        calcFlow();
    }

    int getFlowValue() const { return mFlowValue; }
};

int main(){
    std::unordered_map<int, std::unordered_map<int,int>> flowNetwork;
    int N, M;
    std::cin >> N >> M;
    for (int n = 0; n < N; ++n){
        flowNetwork[n] = std::unordered_map<int,int>();
    }

    for (int m = 0; m < M; ++m){
        int u, v, c;
        std::cin >> u >> v >> c;
        flowNetwork.at(u)[v] = c;
    }

    MaximumFlow mf(flowNetwork, 0, N-1);
    mf.FordFulkerson();
    std::cout << mf.getFlowValue() << std::endl;
}
accuracy: 1
time_ms: 80
memory_kb: 3608
final_rank: 11

code_snippet: #include <iostream>
#include <stack>
using namespace std;

int main(){
  int V, E;
  cin >> V >> E;
  int G[100][100] = {{0}};
  for(int i=0; i<E; i++){
    int u, v, c;
    cin >> u >> v >> c;
    G[u][v] = c;
  }
  int F = 0;
  while(true){
    stack<int> S;
    int d[100] = {0};
    S.push(0);
    d[0] = 1;
    while(!S.empty()){
      int u = S.top();
      int v = -1;
      for(int j=0; j<V; j++){
        if(G[u][j]>0 && d[j]==0){
          v = j;
          break;
        }
      }
      if(v!=-1){
        S.push(v);
        d[v] = 1;
      }else{
        S.pop();
      }
      if(v==V-1){
        break;
      }
    }
    if(S.empty()){
      cout << F << endl;
      return 0;
    }
    F++;
    int s, t;
    s = S.top();
    S.pop();
    while(!S.empty()){
      t = s;
      s = S.top();
      S.pop();
      G[s][t]--;
      G[t][s]++;
    }
  }
}
accuracy: 1
time_ms: 250
memory_kb: 3468
final_rank: 15

code_snippet: // 2025/01/09 Tazoe

#include <iostream>
#include <stack>
using namespace std;

int main()
{
	int V, E;
	cin >> V >> E;
	
	int G[100][100] = {{0}};
	for(int i=0; i<E; i++){
		int u, v, c;
		cin >> u >> v >> c;
		
		G[u][v] = c;
	}
	
	int F = 0;			// フロー
	
	while(true){
		// 深さ優先探索
		stack<int> S;
		int d[100] = {0};
		
		S.push(0);
		d[0] = 1;
		
		while(!S.empty()){
			int u = S.top();
			
			int v = -1;
			for(int j=0; j<V; j++){
				if(G[u][j]>0 && d[j]==0){
					v = j;
					break;
				}
			}
			
			if(v!=-1){
				S.push(v);
				d[v] = 1;
			}
			else{
				S.pop();
			}
			
			if(v==V-1){				// 終点に辿りついたら
				break;
			}
		}
		
		if(S.empty()){			// 終点に辿りつけなかったら終了
			cout << F << endl;
			return 0;
		}
		
		F++;			// フローを増やす
		
		// 行列を書き換える
		int s, t;
		s = S.top();
		S.pop();
		
		while(!S.empty()){
			t = s;
			s = S.top();
			S.pop();
			
			G[s][t]--;
			G[t][s]++;
		}
	}
}
accuracy: 1
time_ms: 250
memory_kb: 3484
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using pll = pair<long long, long long>;

#define v(a,i,b) vector<ll> a(i,b)
#define vv(a,i,j,b) vector<vector<ll>> a(i, vector<ll>(j,b))
#define vp(a,i,b,c) vector<pll>> a(i,{b,c})
#define vvp(a,i,j,b,c) vector<vector<pll>> a(i, vector<>>(j,{b,c}))

#define rrep1(a)          for(ll i = (ll)(a-1); i >= (ll)0 ; i--)
#define rrep2(i, a)       for(ll i = (ll)(a-1); i >= (ll)0; i--)
#define rrep3(i, a, b)    for(ll i = (ll)(a-1); i >=(b); i--)
#define rrep4(i, a, b, c) for(ll i = (ll)(a-1); i >=(b); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define rep1(a)          for(ll i = 0; i < (ll)(a); i++)
#define rep2(i, a)       for(ll i = 0; i < (ll)(a); i++)
#define rep3(i, a, b)    for(ll i = (a); i < (ll)(b); i++)
#define rep4(i, a, b, c) for(ll i = (a); i < (ll)(b); i += (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)

#define fi first
#define se second
#define pb push_back
#define spa " "

//！？！？
#define O print

inline void scan(){}
template<class Head,class... Tail>
inline void scan(Head&head,Tail&... tail){std::cin>>head;scan(tail...);}
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)

//vectorのcin,cout
template<typename T>
std::istream &operator>>(std::istream&is,std::vector<T>&v){for(T &in:v){is>>in;}return is;}
template<typename T>
std::ostream &operator<<(std::ostream&os,const std::vector<T>&v){for(auto it=std::begin(v);it!=std::end(v);){os<<*it<<((++it)!=std::end(v)?" ":"");}return os;}
//dequeのcin,cout
template<typename T>
std::istream &operator>>(std::istream&is,std::deque<T>&v){for(T &in:v){is>>in;}return is;}
template<typename T>
std::ostream &operator<<(std::ostream&os,const std::deque<T>&v){for(auto it=std::begin(v);it!=std::end(v);){os<<*it<<((++it)!=std::end(v)?" ":"");}return os;}
//pairのcin,cout
template<typename T,typename U>
std::ostream &operator<<(std::ostream&os,const std::pair<T,U>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T,typename U>
std::istream &operator>>(std::istream&is,std::pair<T,U>&p){is>>p.first>>p.second;return is;}
//vector<vector<T>>のcout
template<typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<std::vector<T>> &v) {
for (const auto &row : v) {for (auto it = row.begin(); it != row.end(); ++it) { os << *it; if (std::next(it) != row.end()) { os << " "; } } os << "\n";} return os;}

#pragma GCC diagnostic ignored "-Wunused-value"
void print(){cout << '\n';}
template<class T, class... Ts>
void print(const T& a, const Ts&... b){cout << a;(std::cout << ... << (cout << ' ', b));cout << '\n';}
#pragma GCC diagnostic warning "-Wunused-value"

int inf = 2147483647; // おおよそ2*10^9
ll INF = 9223372036854775807; //おおよそ9*10^18
//ull UINF == おおよそ1.8*10^19

struct edge{
    //rev: toから行ける頂点のうち、toから見てfromが何番目に位置するか
    //G[from].size() == rev  
    ll rev, from, to, cap;
};

class fordFulkerson{
public:
    vector<vector<edge>> g;
    vector<bool> used;

    int size = 0;
    void init(int n) {
        g.resize(n);
        used.resize(n);
        size = n;
    }

    void add_edge(ll u, ll v, ll cost){
        g[u].pb({(ll)g[v].size(), u, v, cost});
        g[v].pb({(ll)g[u].size()-1, v, u, 0});
    }

    ll dfs(ll pos, ll goal, ll F){
        if(pos == goal) return F;
        used[pos] = true;

        for(auto &x : g[pos]){
            if(used[x.to] || x.cap <= 0) continue;
            ll d = dfs(x.to, goal, min(F, x.cap));
            if(d > 0){
                x.cap -= d;
                g[x.to][x.rev].cap += d;
                return d;
            }
        }
        return 0;
    }

    ll max_frow(ll start, ll goal){
        ll flow = 0;
        while(true){
            fill(used.begin(), used.end(), false);
            ll f = dfs(start, goal, INF);
            if(f == 0) return flow;
            flow += f;
        }
        return flow;
    }
};

ll n,m;

fordFulkerson ff;

int main(){
    cin >> n >> m;
    ff.init(n);
    rep(m){
        LL(a,b,c);
        ff.add_edge(a,b,c);
    }
    cout << ff.max_frow(0,n-1) << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3712
final_rank: 15