text
stringlengths
49
983k
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int,int> pii; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define all(a) (a).begin(),(a).end() #define pb push_back #define INF (1e9+1) //#define INF (1LL<<59) #define MAX_V 100 struct edge { int to, cap, cost,rev; }; int V; // ????...
#include <bits/stdc++.h> #define pb push_back using namespace std; const int INF=0x3f3f3f3f; const int maxn=105; const int maxq=1005; struct edge{int to,cap,cost,rev;}; int n,m,k; int d[maxn]; int a[maxn]; int p1[maxn]; int p2[maxn]; bool inq[maxn]; vector<edge>G[maxn]; void add_edge(int u,int v,int c,int w) { G[u]...
#include <vector> #include <list> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cc...
#include <iostream> #include <vector> #include <queue> #include <map> #include <algorithm> using namespace std; typedef long long ll; typedef pair<ll,ll> P; const ll inf = 1e14; class min_cost_flow{ private: int N; struct edge{int to; ll cap,cost; int rev; bool is_rev;}; vector<vector<edge>> G; vector<...
#include <bits/stdc++.h> using namespace std; #define int long long // <-----!!!!!!!!!!!!!!!!!!! #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n)-1;i>=0;i--) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define pri...
#include <bits/stdc++.h> using namespace std; #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) #define thd(t) std::get<2>(t) #define fth(t) std::get<3>(t) #define unless(p) if(!(p)) #define until(p) while(!(p)) using ll = long long; using P = std::tuple<int,int>; const int dx[8] = {-1, 1, 0, 0, -1, -1, ...
#include <vector> #include <queue> #define rep(i,n) for(int i=0; i<(n); i++) using namespace std; typedef long long int ll; // Primal-Dual Algorithm // ref: https://tjkendev.github.io/procon-library/python/min_cost_flow/primal-dual.html class MinCostFlow { public: const ll INF = 1e18; const ll MAX_COST = 1e9+9; ...
#define DEBUG 1 #include <iostream> #include <vector> #include <tuple> #include <queue> using namespace std; typedef long long ll; // ------------------------------------------------------------ typedef tuple<ll, int> Info; struct Edge { int to; ll cap, cost; int rev; }; class MinCostFlow { int N; vecto...
#include<iostream> #include<algorithm> #include<vector> #include<queue> #include<cstring> using namespace std; typedef pair<int,int> P;//shortest pass,vertex number const int MAX=100; const int INF=1<<25; class edge { public: int to,cap,cost,rev; edge(){} edge(int to,int cap,int cost,int rev):to(to),cap(cap),cos...
#include<iostream> #include<algorithm> #include<vector> #include<stack> #include<queue> #include<list> #include<string> #include<cstring> #include<cstdlib> #include<cstdio> #include<cmath> #include<ctime> using namespace std; typedef long long ll; bool debug = false; const int NIL = -1; const int INF = 1000000000; co...
#include <algorithm> #include <iostream> #include <limits> #include <vector> using namespace std; typedef int T; // cost type typedef int U; // flow type T INF = numeric_limits<T>::max(); // <limits> struct edge { int to, rev; T cost; U cap; edge(int to, U cap, int rev, T cost) : to(to), rev(rev), c...
#include<iostream> #include<algorithm> #include<vector> using namespace std; const int MAX=100; const int INF=1<<25; class edge { public: int to,cap,cost,rev; edge(){} edge(int to,int cap,int cost,int rev):to(to),cap(cap),cost(cost),rev(rev){} }; int V; vector<edge> G[MAX]; int dist[MAX]; int prevv[MAX],preve[MA...
#include "bits/stdc++.h" using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int, int> PI; typedef pair<LL, LL> PLL; const LL MOD = 1000000007LL; const int inf = 1e9; const LL INF = 1e18; const int MAX_V = 100; struct edge { int to, cap, cost, rev; edge(int to, int cap, int cost, i...
#include<bits/stdc++.h> using namespace std; #define MAX_V 10000 #define INF 1000000001 typedef pair<int,int> P; struct edge { int to,cap,cost,rev; }; int V; vector<edge> G[MAX_V]; int h[MAX_V]; int dist[MAX_V]; int prevv[MAX_V],preve[MAX_V]; void init_edge(){ for(int i=0;i<V;i++)G[i].clear(); } void add_edge(int fro...
#include<iostream> #include<vector> #include<cstring> using namespace std; const int MAX_V = 200; struct edge{ int to, cap, cost, rev; }; int V; vector<edge> G[MAX_V]; int dist[MAX_V]; // 頂点にflowを1流すときのコストの総和 int prevv[MAX_V], preve[MAX_V]; // prev_vertex, prev_edge const int INF = 1<<30; void add_edge(int f...
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, a, b) for (int i = (a); i < (int)(b); ++i) #define rrep(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i) #define all(c) c.begin(),c.end() #define sz(x) ((int)x.size()) using pii = pair<int, int>; using vvi = vector<vector<int>>; u...
#include <bits/stdc++.h> using Int = int64_t; using UInt = uint64_t; using C = std::complex<double>; #define rep(i, n) for(Int i = 0; i < (Int)(n); ++i) #define rep2(i, l, r) for(Int i = (Int)(l); i < (Int)(r); ++i) #define guard(x) if( not (x) ) continue; #ifndef LOCAL_ #define fprintf if( false ) fprintf #endif temp...
#include <bits/stdc++.h> using namespace std; using i64 = long long; #define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++) #define all(x) x.begin(),x.end() struct edge { i64 from; i64 to; i64 cap; i64 cost; i64 rev; }; i64 INF = 1e18; i64 capacity_scaling_bflow(std::vector<std::vector<edge>>& g, std::vect...
//#define __USE_MINGW_ANSI_STDIO 0 #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VL; typedef vector<VL> VVL; typedef pair<int, int> PII; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #defi...
#include <iostream> #include <vector> #include <unordered_map> #include <queue> using namespace std; typedef unordered_map<int,unordered_map<int,int>> double_map; int dfs( int now, int end, int flow, int *cost, vector<bool> &arrived, vector<int> &dp, double_map &g, double_map &costs ) { if(now==end||f...
#include <bits/stdc++.h> using namespace std; using lint = long long; template<class T = int> using V = vector<T>; template<class T = int> using VV = V< V<T> >; template<class T> struct PrimalDual { struct Edge { int to, rev; T cap, cost; }; const int n; const T inf = numeric_limits<T>::max(); VV<Ed...
#include<bits/stdc++.h> using namespace std; using UL=unsigned int; using LL=long long; using ULL=unsigned long long; #define rep(i,n) for(UL i=0; i<(n); i++) template<class T> using nega_queue = priority_queue<T,vector<T>,greater<T>>; struct Edge{ UL u,v; UL c; int d; UL r; }; UL N,M; Edge J[2000]; vector<UL> E[100...
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n)-1;i>=0;i--) #define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--) #define all(a) (a).begin(),(a).end() typedef long long ll; typedef pair<int, int> P; typed...
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(),(x).end() const int mod=1000000007,MAX=103,INF=1<<30; typedef pair<int,int> P; struct edge{int to,cap,cost,rev;}; int V; vector<edge> G[MAX]; int h[MAX]; int dist[MAX]; int prevv[MAX],preve[MAX]; void add_edge(int from,int...
#include <bits/stdc++.h> #define INF 1000000000 using namespace std; typedef pair<int, int> pii; class MinimumCostFlow { struct edge { int to, cap, cost, rev; edge(int to_, int cap_, int cost_, int rev_) : to(to_), cap(cap_), cost(cost_), rev(rev_) {} }; int V; vector<vector<edge>> G; vector<int> h, dist, ...
#include <iostream> #include <algorithm> #include <vector> #include <utility> #include <queue> #include <limits> using namespace std; //BEGIN template <typename T, typename E> struct PrimalDual { struct edge { int to, rev; T cap; E cost; edge() {} edge(int to, T cap, E cost, int rev) :to(to), cap(cap), co...
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; const ull mod = 1e9 + 7; #define REP(i,n) for(int i=0;i<(int)n;++i) //debug #define dump(x) cerr << #x << " = " << (x) << endl; #...
#include <bits/stdc++.h> using namespace std; #define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++) #define debug(x) cerr<<#x<<":"<<x<<endl typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; #define NUM 100 ...
// AOJ GRL_6_B: Network Flow - Minimum Cost Flow #include <bits/stdc++.h> using namespace std; using ll = long long; using Pi = pair<int, int>; using Pl = pair<ll, ll>; using Ti = tuple<int, int, int>; using Tl = tuple<ll, ll, ll>; #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tup...
#include <cstdio> #include <algorithm> #include <vector> #include <queue> using namespace std; using Weight=long long; static const Weight INF=1LL<<57; template <class T> using gp_queue=priority_queue<T, deque<T>, less<T>>; struct Arc { // accessible to the reverse edge size_t src, dst; Weight capacity,...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> struct min_cost_flow_graph { struct edge { int from, to; T cap, f; U cost; }; vector<edge> edges; vector<vector<int>> g; int n, st, fin; T required_flow, flow; U cost; min_cost_flow_graph(int n, int st, int fin, T requi...
#include <algorithm> #include <functional> #include <iostream> #include <queue> #include <vector> using namespace std; namespace Flow { struct Edge { int to, capacity, cost, reverse; Edge(int to, int capacity, int cost, int reverse) : to(to), capacity(capacity), cost(cost), reverse(reve...
//最短経路長が短い経路に流せるだけ流す。 //ただし、順辺のコストをcとしたときに逆辺のコストは-cにする (フローを押し戻すとき、コストも押し戻すため)。 #include <iostream> #include <algorithm> #include <vector> #include <queue> using namespace std; const int VMAX = 100; struct Edge { int from, to, flow, cost, rev; Edge(int from, int to, int flow, int cost, int rev) { this->from = from...
#include<bits/stdc++.h> using namespace std; struct PrimalDual{ const int INF = 1<<28; typedef pair<int,int> P; struct edge{ int to,cap,cost,rev; edge(){} edge(int to,int cap,int cost,int rev):to(to),cap(cap),cost(cost),rev(rev){} }; int V; vector<vector<edge> > G; vector<int> h,dist,prevv,pr...
#include <iostream> #include <vector> #include <numeric> #include <queue> #include <algorithm> #include <utility> #include <functional> using namespace std; //template<typename Int = int> using Int = int; struct PrimalDual { struct Edge { int dst; Int cap, flow, cost; int rev; bool ...
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<bitset> using namespace std; #define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i ) #define rep(i,n) REP(i...
#include <bits/stdc++.h> using Int = int64_t; using UInt = uint64_t; using C = std::complex<double>; #define rep(i, n) for(Int i = 0; i < (Int)(n); ++i) #define rep2(i, l, r) for(Int i = (Int)(l); i < (Int)(r); ++i) #define guard(x) if( not (x) ) continue; #ifndef LOCAL_ #define fprintf if( false ) fprintf #endif temp...
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n)-1;i>=0;i--) #define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--) #define all(a) (a).begin(),(a).end() typedef long long ll; typedef pair<int, int> P; typed...
#include <iostream> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <functional> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> #include <bitset> #include <tuple> #include <cassert> #include <exception> #include <io...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> struct min_cost_flow_graph { struct edge { int from, to; T cap, f; U cost; }; vector<edge> edges; vector<vector<int>> g; int n, st, fin; T required_flow, flow; U cost; min_cost_flow_graph(int n, int st, int fin, T requi...
#include <iostream> #include <vector> #include <algorithm> using namespace std; /* * 最小費用流 * O(FVE) */ struct MinCostFlow{ const int inf = std::numeric_limits<int>::max()/3; struct edge{ int to,cap,cost,rev; edge(){} edge(int t,int ca,int co,int r) : to(t),cap(ca),cost(co),rev(r){} ...
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <functional> #include <cassert> typedef long long ll; using namespace std; #define debug(x) c...
#include <iostream> #include <fstream> #include <cassert> #include <typeinfo> #include <vector> #include <stack> #include <cmath> #include <set> #include <map> #include <string> #include <algorithm> #include <cstdio> #include <queue> #include <iomanip> #include <cctype> #include <random> #include <complex> #define syos...
#include <iostream> #include <vector> #include <utility> #include <queue> #define llint long long #define inf 1e18 using namespace std; typedef pair<llint, llint> P; struct edge{ llint to, cap, cost, rev; edge(){} edge(llint a, llint b, llint c, llint d){ to = a, cap = b, cost = c, rev = d; } }; llint n, m, F;...
#include <iostream> #include <vector> #include <cstring> #include <string> #include <algorithm> #include <iomanip> #include <queue> #include <functional> using namespace std; const int MAX_V = 100010; using Capacity = int; using Cost = int; const auto inf = numeric_limits<Capacity>::max() / 8; struct Edge { int dst; ...
#include <iostream> #include <queue> #include <vector> using namespace std; constexpr int INF = 1000000001; constexpr int MAX = 10000; typedef pair<int, int> P; struct Edge { int to; int cap; int cost; int rev; Edge(int to, int cap, int cost, int rev) : to(to), cap(cap), cost(cost), rev...
#include <bits/stdc++.h> #define _overload(_1,_2,_3,name,...) name #define _rep(i,n) _range(i,0,n) #define _range(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__) #define _rrep(i,n) _rrange(i,n,0) #define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i) #define r...
#include <bits/stdc++.h> using namespace std; using FLOW = int; using COST = int; const int MAX_V = 100; const COST INF = 1000000000; struct Edge { int rev, from, to; FLOW cap, icap; COST cost; Edge(int r, int f, int t, FLOW cp, COST cs) : rev(r), from(f), to(t), cap(cp), icap(cp), cost(cs) {}...
#include<bits/stdc++.h> #define INF 1e9 #define llINF 1e18 #define MOD 1000000007 #define pb push_back #define mp make_pair #define F first #define S second #define ll long long #define ull unsigned long long #define vi vector<ll> #define vvi vector<vi> #define BITLE(n) (1LL<<((ll)n)) #define BITCNT(n) (__builtin_popc...
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define INF 1<<30 #define LINF 1LL<<60 #define MAX_V 100000 struct edge{ int to; int cap; int cost; int rev; edge(){} edge(int to,int cap,int cost,int rev):to(to),cap(cap),c...
#include <vector> #include <queue> #include <set> using namespace std; struct Graph { struct edge { int to; int cap; int cost; int rev; }; int n; vector<vector<edge>> edges; Graph(int N) { n = N; edges.resize(n, vector<edge>()); } int size() const { return n; } vector<edge> ...
#include<bits/stdc++.h> using namespace std; using ll = long long; const int MAX_V = 100; const int INF = 1e9; struct edge { int to,cap,cost,rev; }; int V; vector<edge> G[MAX_V]; int dist[MAX_V]; int prevv[MAX_V],preve[MAX_V]; void add_edge(int from,int to, int cap, int cost) { G[from].push_back((edge){to,cap,cost...
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n)-1;i>=0;i--) #define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--) #define all(a) (a).begin(),(a).end() typedef long long ll; typedef pair<int, int> P; typed...
#include <iostream> #include <cstdio> #include <vector> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<(n);i++) const int INF = 1e9; struct edge { int to, cap, cost, rev; }; int V; const int MAX_V = 100; vector<edge> G[MAX_V]; int dist[MAX_V]; int prev...
#include <math.h> #include <bits/stdc++.h>//一括で読み込み using namespace std; #define MAX_V 500 typedef long long ll; typedef pair<int,int> P; struct edge{int to, cap, cost, rev;}; int V; vector<edge> G[MAX_V]; int h[MAX_V]; int dist[MAX_V]; int prevv[MAX_V],preve[MAX_V]; void add_edge(int from, int to, int cap, int cos...
#include <bits/stdc++.h> #define fread_siz 1024 inline int get_c(void) { static char buf[fread_siz]; static char *head = buf + fread_siz; static char *tail = buf + fread_siz; if (head == tail) fread(head = buf, 1, fread_siz, stdin); return *head++; } inline int get_i(void) { register int ret = 0; register...
//#include "bits/stdc++.h" #define _USE_MATH_DEFINES #include <cmath> #include <cstdlib> #include <deque> #include <algorithm> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <util...
#include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <string> #include <vector> #include <random> #include <bitset> #include <queue> #include <cmath> #include <stack> #include <set> #include <map> typedef long long ll; using namespace std; const ll MOD = 1000000007LL; typedef pair <i...
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int,int> pii; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define all(a) (a).begin(),(a).end() #define pb push_back #define INF (1e9+1) //#define INF (1LL<<59) #define MAX_V 100 struct edge { int to, cap, cost,rev; }; int V; // ????????...
#define _USE_MATH_DEFINES #include <iostream> #include <fstream> #include <cstdio> #include <cmath> #include <cstdlib> #include <cstring> #include <string> #include <vector> #include <utility> #include <complex> #include <set> #include <map> #include <queue> #include <stack> #include <deque> #include <tuple> #include <...
#include <cstdio> #include <algorithm> #include <vector> #include <queue> using namespace std; using Weight=long long; static const Weight INF=1LL<<57; template <class T> using gp_queue=priority_queue<T, deque<T>, less<T>>; struct Arc { // accessible to the reverse edge size_t src, dst; Weight capacity,...
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; constexpr int IINF = INT_MAX; struct edge{ int to, cap, cost, rev; }; int V, E, F; vector<vector<edge> > G; vector<int> h, dist, prevv, preve; void add_edge(int from, int to, int cap, int cost){ G[from].push_back((edge){to, cap, cost, i...
#include <bits/stdc++.h> #define pb push_back using namespace std; const int INF=0x3f3f3f3f; const int maxn=105; struct Edge { int from,to,cap,flow,cost; Edge(int u,int v,int c,int f,int w):from(u),to(v),cap(c),flow(f),cost(w) {} }; int n,m,tf; vector<Edge>edges; vector<int>G[maxn]; bool inq[maxn]; int d[maxn]; int...
#include <bits/stdc++.h> using namespace std; struct PrimalDual{ const int INF = 1<<28; typedef pair<int,int> P; struct edge{ int to,cap,cost,rev; edge(){} edge(int to,int cap,int cost,int rev):to(to),cap(cap),cost(cost),rev(rev){} }; int n; vector<vector<edge> > G; vector<int> h,dist,prevv,...
#include<iostream> using namespace std; //Minimum Cost Flow O(FE log V) #include<algorithm> #include<utility> #include<vector> #include<queue> #include<limits> template<typename T> struct MCF{ vector<vector<pair<pair<int,int>,pair<int,T> > > >G; vector<T>h,d; vector<int>pv,pe; MCF(int n_=0):G(n_),h(n_,0),d(n_),pv(n...
#include <bits/stdc++.h> using namespace std; #define int long long //O(F*V^2) class MinimumCostFlow { private: struct edge { int to, cap, cost, rev; }; const int INF = 1e18; int V; vector<vector<edge>> G; vector<int> h, dist; vector<int> prevv, preve; void add_edge(int from, int to, int cap, i...
#include <bits/stdc++.h> using namespace std; #define rep(i,n) REP(i,0,n) #define REP(i,s,e) for(int i=(s); i<(int)(e); i++) #define repr(i, n) REPR(i, n, 0) #define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--) #define pb push_back #define all(r) r.begin(),r.end() #define rall(r) r.rbegin(),r.rend() #def...
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_B&lang=jp #include <iostream> #include <map> #include <queue> #include <vector> #include <algorithm> using namespace std; typedef pair<int, int>P; class MCF{ public: class edge{ public: int to, cap, cost, rev; edge(){}; edge(int _to, int _cap, ...
#include <bits/stdc++.h> #define _overload(_1,_2,_3,name,...) name #define _rep(i,n) _range(i,0,n) #define _range(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__) #define _rrep(i,n) _rrange(i,n,0) #define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i) #define r...
#include<bits/stdc++.h> #define fi first #define se second typedef long long ll; using namespace std; //BEGIN CUT HERE //Min_cost_flow class Min_cost_flow{ public: explicit Min_cost_flow(int n):vertex(static_cast<unsigned int>(n+10)){ G.resize(vertex); prev_e.resize(vertex); prev_v.resize(v...
#include <bits/stdc++.h> static const int MAX=100; static const int INFTY=(1<<30); class edge{ public: int target, cap, cost, rev; edge(int target = 0, int cap =0, int cost = 0, int rev =0) : target(target), cap(cap), cost(cost), rev(rev) {} }; int V; std::vector<edge> G[MAX]; int h[MAX], dist[MAX], prevv[MAX],...
#include <iostream> #include <fstream> #include <string> #include <vector> #include <queue> #include <stack> #include <map> #include <algorithm> #include <sstream> #include <cmath> #include <set> #include <iomanip> #include <deque> #include <stdio.h> using namespace std; #define REP(i,n) for(int (i)=0;(i)<(int)(n);(i...
#include <cassert> #include <iostream> #include <vector> #include <queue> #include <utility> #include <tuple> #include <limits> using namespace std; struct MinCostFlowGraph { private: using ll = long long; struct edge { int to; ll cap, cost; int r_idx; edge(int t, ll cap, ll cost, int r) : to...
#include <bits/stdc++.h> using namespace std; template<typename T, T INF> class MinCostFlow{ public: //辺を表す構造体(行き先、容量、コスト、逆辺) struct edge{ int to,cap; T cost; int rev; edge(); edge(int to,int cap,T cost,int rev):to(to),cap(cap),cost(cost),rev(rev){} }; int V; ...