Search is not available for this dataset
name
stringlengths
2
88
description
stringlengths
31
8.62k
public_tests
dict
private_tests
dict
solution_type
stringclasses
2 values
programming_language
stringclasses
5 values
solution
stringlengths
1
983k
p02226 Test
test UnionFind(バイナリ入力) Example Input Output
{ "input": [ "" ], "output": [ "" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
p02226 Test
test UnionFind(バイナリ入力) Example Input Output
{ "input": [ "" ], "output": [ "" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> namespace procon { class UnionFind { private: struct nodeinfo { int par; int rank; nodeinfo(int par) : par(par), rank(0) {} }; std::vector<nodeinfo> node; public: UnionFind(int n) : node() { node.reserve(n); for (int i = 0; i < n; ++i) { node.push_back(nodei...
p02226 Test
test UnionFind(バイナリ入力) Example Input Output
{ "input": [ "" ], "output": [ "" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
print(2)
p02226 Test
test UnionFind(バイナリ入力) Example Input Output
{ "input": [ "" ], "output": [ "" ] }
{ "input": [], "output": [] }
IN-CORRECT
python3
print(1)
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; struct SuccessiveShortestPath { struct Edge{ int to, cap, cost, rev; }; int n, init; vector<vector<Edge>> g; vector<int> dist, pv, pe, h; SuccessiveShortestPath() {} SuccessiveShortestPath(int n, int INF = 1e9) : n(n), g(n), init(INF), dist(n), pv(n), pe(n...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; long long INF = 1000000000000000; long long primal_dual(vector<map<int, pair<long long, int>>> &E, int s, int t, long long F){ int V = E.size(); for (int i = 0; i < V; i++){ for (auto edge : E[i]){ if (!E[edge.first].count(i)){ E[edge.first][i] = make_pair(0, -ed...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <cstdio> #include <cstring> #include <string> #include <cmath> #include <cassert> #include <iostream> #include <algorithm> #include <stack> #include <queue> #include <vector> #include <set> #include <map> #include <bitset> using namespace std; #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.util.*; public class Main implements Runnable { private static int MOD = 1_000_000_007; public static void main(String[] args) { // Run with 32MB stack Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024); thread.start(); } @Override public void ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> struct min_cost_flow_graph_bellman_ford { 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_bellman_ford(int n...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int v, e; vector<pair<int, int> > adj[110], revadj[110]; int capacity[1010], cost[1010], flowingthrough[1010], dis[110], pre[110], preedge[110], endofedge[1010]; void bellmanford() { fill_n(dis, v, 1e9); dis[0] = 0; for (int f = 0; f < v; f++) { for (int i = 0; i < v;...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using lint = long long int; using ulint = unsigned long long int; template<class T = int> using V = vector<T>; template<class T = int> using VV = V< V<T> >; template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); } tem...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<iostream> #include<set> #include<vector> #include<queue> #include<map> 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 stru...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; using vi = vector<i64>; using vvi = vector<vi>; template<typename flow_t = int, typename cost_t = int> struct PrimalDual { const cost_t INF; struct edge { int to; flow_t cap; cost_t cost; int rev; bool is...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<iostream> #include<vector> #include<queue> using namespace std; typedef long long ll; typedef pair<ll,ll> P; #define rep(i,n) for(int i=0;i<(n);i++) struct edge { ll to;//行き先の頂点 ll cap;//辺の容量 ll cost;//1フローあたりのコスト ll rev;//逆辺のインデックス(G[e.to][e.rev]で逆辺にアクセスできる。) }; #define MAX_V 1000 #define...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; using Int = long long; //BEGIN CUT HERE 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<...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.io.*; import java.util.*; public class Main implements Runnable{ private ArrayList<ArrayList<Integer>> graph; private Edge[] edges; public static void main(String[] args) throws Exception { new Thread(null, new Main(), "bridge", 16 * 1024 * 1024).start(); } @Override public...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i)) using ll = long long; using P = pair<int, int>; using namespace std; const double EPS = 1e-9; const int MOD = 1e9+7; const int INF = 2e5; const double PI = acos(-1.0); using namespace std; struct MinCostFlow { str...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <vector> #include <numeric> #include <queue> #include <algorithm> #include <utility> #include <functional> using namespace std; const int MAX_V = 100010; using Flow = int; const auto inf = numeric_limits<Flow>::max() / 8; struct Edge { int dst; Flow cap, cap_orig; Flow cost; ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <vector> #include <queue> #include <limits> using namespace std; template <typename T> class MinCostFlow { public: MinCostFlow(int n) : n(n), capacity(n, vector<T>(n)), cost(n, vector<T>(n)), prev(n) {} void add_edge(int src, int dst, T cap, T c) { capacity[src][dst] = cap; ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <cstdio> #include <vector> #include <queue> #include <tuple> int v, e; struct Edge { Edge() {} Edge(int from, int to, int capacity, int cost, int rev) : from(from), to(to), capacity(capacity), cost(cost), rev(rev) {} int from, to; int capacity; int cost; int rev; }; std::vector<Edge> edges[128];...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.util.*; public class Main { @SuppressWarnings("unchecked") static class MinCostFlow{ class Edge{ int to,cap,cost,rev; Edge(int to,int cap,int cost,int rev){this.to=to;this.cap=cap;this.cost=cost;this.rev=rev;} } List<Edge> edges[]; void add_edge(int from,int to,int cap,int ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#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> >; // BEGIN CUT HERE template<class T> struct PrimalDual { struct Edge { int to, rev; T cap, cost; }; const T inf = numeric_limits<T>::max(); const int n; ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
python3
# ノードをtupleで渡す from collections import defaultdict from heapq import * class MinCostFlow: def __init__(self): self.inf=10**9 self.to = defaultdict(dict) def add_edge(self, u, v, cap, cost): self.to[u][v]=[cap, cost] self.to[v][u]=[0, -cost] # s...source,t...sink,f...flow ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#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; // ????...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
python3
import heapq class MinCostFlow: class Edge: def __init__(self,to,cap,rev,cost): self.to = to self.cap = cap self.rev = rev self.cost = cost def __init__(self,n,inf=1000000007): self.n = n self.inf = inf self.e = [[] for _ in range...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
python3
import sys input = sys.stdin.readline from heapq import heappush, heappop def min_cost_flow_dijkstra(E, s, t, f): INF = 1 << 100 NN = N LN = NN.bit_length() G = [[] for _ in range(NN)] for a, b, cap, c in E: G[a].append([b, cap, c, len(G[b])]) G[b].append([a, 0, -c, len(G[a])-1]) ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <cstdio> #include <vector> #include <algorithm> #include <queue> #define REP(i,n) for(int i=0;i<(int)n;++i) #define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) #define ALL(c) (c).begin(), (c).end() #define INF 99999999 using namespace std; typedef int Weight; struct Edge { int src, dst...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <typename Cap, typename Cost> struct Graph { const Cost INF = numeric_limits<Cost>::max(); struct Edge { int to, rev; Cap cap; Cost cost; Edge(int to, Cap cap, Cost cost, int rev) : to(to), cap(cap), cost(cost), rev(rev) {} }; vector<...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
python3
class MinCostFlow: def __init__(self, n): self.n = n self.G = [[] for i in range(n)] def addEdge(self, f, t, cap, cost): # [to, cap, cost, rev] self.G[f].append([t, cap, cost, len(self.G[t])]) self.G[t].append([f, 0, -cost, len(self.G[f])-1]) def minCostFlow(self, s...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES //#include "MyMath.h" //#include "MyDisjointset.h" #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <functional> #include <stdio.h> #include <math.h> #include <string.h> using namespace std; typedef pair<int, int> P; typedef l...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.PriorityQueue; import java.util.Scanner; @SuppressWarnings("unchecked") class MinCostFlow{ class Edge{ int to,cap,cost,rev; Edge(int to,int cap,int cost,int rev){this.to=to;this.cap=cap;this.cost=cost;this....
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#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...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#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...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <vector> #include <queue> #define INF (1 << 30) using namespace std; struct Edge { //to : Edge(from ??? to) cap:capacity cost:cost rev:reverse int to, cap, cost, rev; Edge(int to, int cap, int cost, int rev) :to(to), cap(cap), cost(cost), rev(rev) {} }; #define P vector<vector<Edge>> ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector<int> VI; typedef vector<ll> VL; typedef ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
//#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...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.InputMismatchException; import java.util.TreeSet; public class Main { static InputStream is; static PrintWriter out; static ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdint> #include <cstdio> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#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]...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<iostream> #include<vector> #include<algorithm> #include<queue> #define NMAX 110 #define CMAX 1000000007 using namespace std; typedef pair<int, int> pii; int c[110][110] = {0}; int d[110][110] = {0}; int dist[110]; int path[110]; int Dijkstra(vector<int> *g, int s, int t){ priority_queue<pair<int, pii>, v...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.util.*; import java.io.*; import java.awt.geom.*; import java.math.*; public class Main { static final Scanner in = new Scanner(System.in); static final PrintWriter out = new PrintWriter(System.out,false); static boolean debug = false; static int primalDual(int[][][] cost, int[][][] capacity, int sou...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< "...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<cstdio> #include<vector> #include<algorithm> #include<utility> #include<numeric> #include<iostream> #include<array> #include<string> #include<sstream> #include<stack> #include<queue> #include<list> #include<functional> #define _USE_MATH_DEFINES #include<math.h> #include<map> #define INF 200000000 using name...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#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]...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<iostream> #include<vector> #include<algorithm> #include<queue> 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(in...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include "bits/stdc++.h" using namespace std; #define all(x) x.begin(), x.end() #define mp make_pair #define pii pair<int, int> #define pll pair<long long, long long> #define ll long long static const int INF = 0x3f3f3f3f; struct edge { int to, cap, cost, rev; }; int V; vector<edge> g[1010...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include "bits/stdc++.h" using namespace std; class minCostFlow { using type = int; using pii = std::pair<int, int>; const int INF = 1e9; struct Edge { type to, cap, cost, rev; Edge(type to_, type cap_, type cost_, type rev_) : to(to_), cap(cap_), cost(cost_), rev(rev_)...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define pb push_back using namespace std; const int INF=0x3f3f3f3f; const int maxn=105; 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].pb(edge{v,c,w,int(G[...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
// this program implements Dinitz's algorithm #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> const int N = 110; const int M = 2010; const int inf = 0x3fffffff; struct Edge { int to, cap, cost, next; } es[M]; int S, T; // source, sink int SIZE = 0; // number of edges int h[N]; // poin...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <stdio.h> #include <cmath> #include <algorithm> #include <cfloat> #include <stack> #include <queue> #include <vector> #include <string> #include <iostream> #include <set> #include <map> #include <time.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define MOD 100000...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.io.*; import java.util.*; public class Main implements Runnable{ private ArrayList<ArrayList<Integer>> graph; private Edge[] edges; public static void main(String[] args) throws Exception { new Thread(null, new Main(), "bridge", 16 * 1024 * 1024).start(); } @Override public...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a;i<b;i++) #define ZERO(a) memset(a,0,sizeof(a)) template<int NV, class V> class MinCostFlow { public: struct edge { int to, capacity; V cost; int reve; edge(int a, int b, V c, int d) { to = a; capacity = b; cost = c; reve = d; } };...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define pb push_back #define all(v) (v).begin(),(v).end() #define fi first #define se second typedef vector<int>vint; typedef pair<int,int>pint; typedef vector<pint>vpint; template<typename A,typename B>inline void chmin(A &a,B b){if...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using VI = vector<int>; using VVI = vector<VI>; using PII = pair<int, int>; using LL = long long; using VL = vector<LL>; using VVL = vector<VL>; using PLL = pair<LL, LL>; using VS = vector<string>; #define ALL(a) begin((a)),end((a)) #define RALL(a) (a).rbegin(), (a).rend...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
/* 負の閉路が存在しない場合に使える O(FElogV) 参考: 蟻本p202 https://ei1333.github.io/luzhiled/snippets/graph/primal-dual.html verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_B&lang=jp */ #include <bits/stdc++.h> using namespace std; template<typename flow_t,typename cost_t> struct PrimalDual{ struct edge{ ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG_MODE #define DBG(n) n; #else #define DBG(n) ; #endif #define REP(i,n) for(ll (i) = (0);(i) < (n);++i) #define PB push_back #define MP make_pair #define FI first #define SE second #define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << end...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <vector> #include <limits> template <class Cap, class Cost, bool isDirect> class MinCostFlow { struct Edge { int from, to; Cap cap; Cost cost; int rev; Edge(int from, int to, Cap cap, Cost cost, int rev) : from(from), to(to), cap(cap)...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
python3
#最小費用流問題 import sys readline = sys.stdin.buffer.readline def even(n): return 1 if n%2==0 else 0 n,m,f = map(int,readline().split()) """ n頂点m辺の重み付き有向グラフに流量fを流したい。 コストの最小値を出力せよ。 但しsourse = 0,sink = n-1とし、 そもそも流量f流せるだけcapacityがない場合は-1を出力せよ。 """ # 最小費用流(minimum cost flow) class MinCostFlow: def __init__(self, n): ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<cstdio> #include<vector> #include<algorithm> #include<utility> #include<numeric> #include<iostream> #include<array> #include<string> #include<sstream> #include<stack> #include<queue> #include<list> #include<functional> #define _USE_MATH_DEFINES #include<math.h> #include<map> #define INF 200000000 using name...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
python3
from heapq import heappush, heappop class MinimumCostFlow: inf = 1000000000 def __init__(self, n): self.n = n self.edges = [[] for i in range(n)] def add_edge(self, f, t, cap, cost): self.edges[f].append([t, cap, cost, len(self.edges[t]), False]) self.edges[t].append([f, 0, ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<iostream> #include<vector> #include<algorithm> #include<string> #include<map> #define _USE_MATH_DEFINES #include<math.h> #include<queue> #include<deque> #include<stack> #include<cstdio> #include<utility> #include<set> #include<list> #include<cmath> #include<stdio.h> #include<string.h> #include<iomanip> #includ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <vector> #include <unordered_map> #include <queue> using namespace std; int v,e,f; unordered_map<int,unordered_map<int,int> > g,costs,inv_costs; queue<pair<int,int> > nodes; int cost = 0; int dfs(int now, int flow, vector<bool> &arrived, vector<int> &dp) { if(now==0||flow==0) return flo...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int INF = (int) 1e5 + 1; const int MAX_V = (int) 100; struct edge { int to, cap, cost, rev; }; 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, ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, j) for(int i = 0; i < (int)(j); i++) constexpr int INF = 1 << 28; struct Edge { int to; ll capacity, cost, rev; }; constexpr ll INFL = 1LL << 60; struct Flow { int N; vector<vector<Edge>> E; Flow(int n) : N(n) { ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <vector> #include <numeric> #include <queue> #include <algorithm> #include <utility> #include <functional> using namespace std; using Flow = int; template<typename Flow = int> struct PrimalDual { struct Edge { int dst; Flow cap, cap_orig; Flow cost; in...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
bool debug=false; #include <string.h> #include <stdio.h> #include <queue> #include <vector> #include <utility> using namespace std; #define F first #define S second #define PB push_back const int INF=1e9+10; const int N=1e2+10; pair<int,int> graph[N][N]; pair<int,int> dis[N]; int from[N]; int n; int min(int a,int b){re...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<cstdio> #include<cstring> #include<vector> #include<queue> #include<algorithm> #include<cmath> #include<climits> #include<string> #include<set> #include<map> #include<iostream> using namespace std; #define rep(i,n) for(int i=0;i<((int)(n));i++) #define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++) #define...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #ifdef _DEBUG #include "dump.hpp" #else #define dump(...) #endif //#define int long long #define DBG 1 #define rep(i, a, b) for (int i = (a); i < (b); i++) #define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--) #define loop(n) rep(loop, (0), (n)) #...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> #include <iomanip> using namespace std; typedef long long LL; typedef long double LD; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef pair<LD, LD> PLDLD; typedef vector<int> VI; typedef vector<char> VB; #define FOR(i,a,b) for(int i=(a);i<(int)(b);++i) #define REP(i,n) FOR(i...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
//最小費用流問題を解く //計算量O(F|V||E|) //参考 蟻本 #include<iostream> #include<vector> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<(n);i++) struct edge { ll to;//行き先の頂点 ll cap;//辺の容量 ll cost;//1フローあたりのコスト ll rev;//逆辺のインデックス(G[e.to][e.rev]で逆辺にアクセスできる。) }; #define MAX_V 1000 #define ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
python3
V,E,F=map(int,input().split()) EDGE=dict() EDGE2=[[] for i in range(V)] for i in range(E): x,to,c,d=map(int,input().split()) EDGE[(x,to)]=[c,d] EDGE2[x].append(to) BACK=[-1]*V P=[0]*V # 一回ベルマンフォードをしてポテンシャルを求める. ANS=[float("inf")]*V ANS[0]=0 for rep in range(V): for x,to in EDGE: c,d=EDG...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
python3
INF = float('inf') def trace_back(sink, predecessors): p = predecessors[sink] while p is not None: v, i = p yield edges[v][i] p = predecessors[v] def min_cost_flow(source, sink, required_flow): res = 0 while required_flow: dist = [INF] * n dist[source] = 0 ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <cstdio> #include <vector> #include <queue> #include <tuple> int v, e; struct Edge { Edge() {} Edge(int from, int to, int capacity, int cost, int rev) : from(from), to(to), capacity(capacity), cost(cost), rev(rev) {} int from, to; int capacity; int cost; int rev; }; std::vector<Edge> edges[128];...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> #define range(i,a,b) for(int i = (a); i < (b); i++) #define rep(i,b) for(int i = 0; i < (b); i++) #define all(a) (a).begin(), (a).end() #define show(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; const i...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <vector> #include <queue> #include <utility> using namespace std; typedef pair<int, int> P; struct edge{ int to; int cap; int cost; int rev; }; struct PDijk{ int V; int INF; vector<int> pote, prevv, preve; vector<vector<edge>> G; PDijk(int N){ V =...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#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__) template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;} template<class T>bool chmin...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; template< typename flow_t, typename cost_t > struct PrimalDual { const cost_t INF; struct edge { int to; flow_t cap; cost_t cost; int rev; }; vector< vector< edge > > graph; vector< cost_t > potential, min_cost; vector< int > prevv, preve; P...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#line 1 "test/aoj/GRL_6_B.test.cpp" #define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_b" #line 2 "test/aoj/../../graph/min-cost-flow.hpp" #include <algorithm> #include <vector> #include <queue> struct min_cost_flow { struct edge { int to, cap, cost, rev; }; using P = std::pair<int, in...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vint; typedef pair<int,int> pint; typedef vector<pint> vpint; #define rep(i,n) for(int i=0;i<(n);i++) #define REP(i,n) for(int i=n-1;i>=(0);i--) #define reps(i,f,n) for(int i=(f);i<(n);i++) #define each(it,v) for(__typeof((v).begin(...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for (ll i=0;i<(n);++i) const ll MOD=1e9+7; template<typename T,typename E> struct PrimalDual{ const E inf=numeric_limits<E>::max()/2; struct edge{ int to,rev; T cap; E cost; edge(int to,T cap,E cost,int rev): ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; #define MAX_V 500 #define 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<edge> G[MAX_V]; int h[MAX_V]; int dist[MAX_V]; int prevv[MAX_V],preve[M...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <cstdio> // printf(), scanf() #include <vector> #include <algorithm> // min(), fill() using namespace std; static const int MAX_V = 100; static const int INF = 100000000; typedef struct edge_tbl { int to, cap, cost; unsigned long rev; } edge; vector<edge> G[MAX_V]; int dist[MAX_V]; int pr...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#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; // ????...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
python3
from heapq import heappush, heappop class MinCostFlow: INF = 10**18 def __init__(self, N): self.N = N self.G = [[] for i in range(N)] def add_edge(self, fr, to, cap, cost): G = self.G G[fr].append([to, cap, cost, len(G[to])]) G[to].append([fr, 0, -cost, len(G[fr])-...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <algorithm> #include <tuple> #include <iostream> #include <vector> using namespace std; #define MAX_V 200 #define INF 1000000 typedef tuple<int,int,int,int> Edge; // to,cap,cost,rev int V; typedef vector<Edge> Vertex; vector<Vertex> G(MAX_V); int dist[MAX_V]; int prev_v[MAX_V], prev_e[MAX_V]; void add_edge(...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using ll = long long; using namespace std; constexpr ll inf = 1e15; constexpr ll mod = 1e9+7; struct Edge { int to; int cap; int cost; int rev; }; vector<Edge> edges[101]; int primalDual(int s, int t, int f) { int ret = 0; priority_queue<pair<int, int>, vector<pair<in...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <vector> #include <queue> #include <iostream> using namespace std; #define MAX_E 1001 int V, E, F, US[MAX_E], VS[MAX_E], CAP[MAX_E], COST[MAX_E]; class MinCostFlow { public: const int INFTY = (1 << 21); struct Edge { int t, cap, cost, rev; }; struct P { int d, id; bool operator < (const P &othe...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <vector> #include <algorithm> #include <queue> using namespace std; static const int MAX_V = 110; static const int INF = (1<<30); typedef pair<int, int> P; struct edge{ int to, cap, cost, rev;}; int V; vector<edge> G[MAX_V]; int h[MAX_V], dist[MAX_V], prevv[MAX_V], preve[MAX_V]; void ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
python3
from collections import defaultdict v_num, e_num, flow = (int(n) for n in input().split(" ")) edges = defaultdict(list) for _ in range(e_num): s1, t1, cap, cost = (int(n) for n in input().split(" ")) edges[s1].append([t1, cap, cost, len(edges[t1])]) edges[t1].append([s1, 0, -cost, len(edges[s1]) - 1]) answ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; #if __has_include("print.hpp") #include "print.hpp" #endif #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define MOD 1000000007 template<class T> inline bool chmax(T& a, T b) { if (a <...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.io.InputStream; import java.io.FileNotFoundException; import java.util.Comparator; import java.util.PriorityQueue; import java.io.IOException; import java.util.Queue; import java.util.Arrays; import java.util.ArrayList; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.List; import j...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include<bits/stdc++.h> using namespace std; #define INF 1e9 struct edge{ //行先、容量、コスト、逆辺 int to,cap,cost,rev; }; void add_edge(int from,int to,int cap ,int cost,vector<vector<edge> > &g){ g[from].push_back( (edge) { to,cap,cost,(int)g[to].size() } ); g[to].push_back( (edge){from,0, -cost,(int)g[from].size()-1}); ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template<class T> struct min_cost_flow { using value_type = T; using P = pair<value_type, int>; private : const value_type INF = numeric_limits<value_type>::max(); struct edge { public : int to, rev; value_type cap; value_type cost; edge (int to, value_type...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> P; typedef pair<ll, ll> Pll; typedef vector<int> Vi; //typedef tuple<int, int, int> T; #define FOR(i,s,x) for(int i=s;i<(int)(x);i++) #define REP(i,x) FOR(i,0,x) #define ALL(c) c.begin(), c.end() #define DUMP( x ) cerr << #x...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
java
import java.io.*; import java.util.*; public class Main implements Runnable{ private ArrayList<ArrayList<Integer>> graph; private Edge[] edges; public static void main(String[] args) throws Exception { new Thread(null, new Main(), "bridge", 16 * 1024 * 1024).start(); } @Override public...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; template <typename Flow, typename Cost> class PrimalDual { private: Cost INF_COST = std::numeric_limits<Cost>::max(); public: struct Edge { int to; Flow cap; Cost cost; int rev; Edge () {} Edge (int t, Flow f, Cost c, in...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> using namespace std; typedef long long int64; const int MAX_V = 1e5 + 1; const int INF = 1e9 + 1; typedef pair< int, int > P; // O(|E||V|^2) struct Edge { Edge(int _to, int _cap, int _cost, int _rev) : to(_to), cap(_cap), cost(_cost), rev(_rev) {} int to, cap, cost, rev; // 逆辺 }; in...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
python3
import heapq as hp class MinimumCostFlow(): def __init__(self, N, INF=10**18): self.graph = [{} for _ in range(N)] self.N = N self.INF = INF def add_edge(self, u, v, cap, cost, undirected=False): # u -> v (maxflow, cost) if cap == 0: return if undirected: ...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <cmath> #include <queue> using namespace std; template<class T> struct PrimalDual { struct Edge { int to, rev; T cap, cost; Edge () {} Edge (int _to, T _cap, T _cost, int _rev) : to(_to), cap(_cap), cost(_co...
p02377 Minimum Cost Flow
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "" ], "output": [ "6", "" ] }
{ "input": [], "output": [] }
CORRECT
cpp
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back using namespace std; typedef pair <int, int> pii; const int INF = 0x3f3f3f3f; int n, e, f, c[1005][1005]; vector <pii> adj[1005]; int dij(int s, int t, vector <int> &p, vector <int> &d) { // cout << "WTFF" << endl; ...