const int mxN = 55 ;
const int inf = 2e9 ;
struct Edgee {
int to, cost, cap, flow, backEdge;
} ;
struct MCMF {
int s, t, n;
vector< Edgee> g[ mxN] ;
MCMF( int _s, int _t, int _n) {
s = _s, t = _t, n = _n;
}
void addEdge( int u, int v, int cost, int cap) {
Edgee e1 = { v, cost, cap, 0 , g[ v] .size ( ) } ;
Edgee e2 = { u, - cost, 0 , 0 , g[ u] .size ( ) } ;
g[ u] .push_back ( e1) ; g[ v] .push_back ( e2) ;
}
pair< int , int > minCostMaxFlow( ) {
int flow = 0 , cost = 0 ;
vector< int > state( n) , from( n) , from_edge( n) , d( n) ;
deque< int > q;
while ( true ) {
for ( int i = 0 ; i < n; i++ )
state[ i] = 2 , d[ i] = inf, from[ i] = - 1 ;
state[ s] = 1 ; q.clear ( ) ; q.push_back ( s) ; d[ s] = 0 ;
while ( ! q.empty ( ) ) {
int v = q.front ( ) ; q.pop_front ( ) ; state[ v] = 0 ;
for ( int i = 0 ; i < ( int ) g[ v] .size ( ) ; i++ ) {
Edgee e = g[ v] [ i] ;
if ( e.flow >= e.cap || d[ e.to ] <= d[ v] + e.cost )
continue ;
int to = e.to ; d[ to] = d[ v] + e.cost ;
from[ to] = v; from_edge[ to] = i;
if ( state[ to] == 1 ) continue ;
if ( ! state[ to] || ( ! q.empty ( ) && d[ q.front ( ) ] > d[ to] ) )
q.push_front ( to) ;
else q.push_back ( to) ;
state[ to] = 1 ;
}
}
if ( d[ t] == inf) break ;
int it = t, addflow = inf;
while ( it ! = s) {
addflow = min( addflow,
g[ from[ it] ] [ from_edge[ it] ] .cap
- g[ from[ it] ] [ from_edge[ it] ] .flow ) ;
it = from[ it] ;
}
it = t;
while ( it ! = s) {
g[ from[ it] ] [ from_edge[ it] ] .flow + = addflow;
g[ it] [ g[ from[ it] ] [ from_edge[ it] ] .backEdge ] .flow - = addflow;
cost + = g[ from[ it] ] [ from_edge[ it] ] .cost * addflow;
it = from[ it] ;
}
flow + = addflow;
}
return { cost,flow} ;
}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emUoKTsgaSsrKSB7CiAgICAgICAgICBFZGdlZSBlID0gZ1t2XVtpXTsKICAgICAgICAgIGlmIChlLmZsb3cgPj0gZS5jYXAgfHwgZFtlLnRvXSA8PSBkW3ZdICsgZS5jb3N0KQogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIGludCB0byA9IGUudG87IGRbdG9dID0gZFt2XSArIGUuY29zdDsKICAgICAgICAgIGZyb21bdG9dID0gdjsgZnJvbV9lZGdlW3RvXSA9IGk7CiAgICAgICAgICBpZiAoc3RhdGVbdG9dID09IDEpIGNvbnRpbnVlOwogICAgICAgICAgaWYgKCFzdGF0ZVt0b10gfHwgKCFxLmVtcHR5KCkgJiYgZFtxLmZyb250KCldID4gZFt0b10pKQogICAgICAgICAgICBxLnB1c2hfZnJvbnQodG8pOwogICAgICAgICAgZWxzZSBxLnB1c2hfYmFjayh0byk7CiAgICAgICAgICBzdGF0ZVt0b10gPSAxOwogICAgICAgIH0KICAgICAgfQogICAgICBpZiAoZFt0XSA9PSBpbmYpIGJyZWFrOwogICAgICBpbnQgaXQgPSB0LCBhZGRmbG93ID0gaW5mOwogICAgICB3aGlsZSAoaXQgIT0gcykgewogICAgICAgIGFkZGZsb3cgPSBtaW4oYWRkZmxvdywKICAgICAgICAgICAgZ1tmcm9tW2l0XV1bZnJvbV9lZGdlW2l0XV0uY2FwCiAgICAgICAgICAgIC0gZ1tmcm9tW2l0XV1bZnJvbV9lZGdlW2l0XV0uZmxvdyk7CiAgICAgICAgaXQgPSBmcm9tW2l0XTsKICAgICAgfQogICAgICBpdCA9IHQ7CiAgICAgIHdoaWxlIChpdCAhPSBzKSB7CiAgICAgICAgZ1tmcm9tW2l0XV1bZnJvbV9lZGdlW2l0XV0uZmxvdyArPSBhZGRmbG93OwogICAgICAgIGdbaXRdW2dbZnJvbVtpdF1dW2Zyb21fZWRnZVtpdF1dLmJhY2tFZGdlXS5mbG93IC09IGFkZGZsb3c7CiAgICAgICAgY29zdCArPSBnW2Zyb21baXRdXVtmcm9tX2VkZ2VbaXRdXS5jb3N0ICogYWRkZmxvdzsKICAgICAgICBpdCA9IGZyb21baXRdOwogICAgICB9CiAgICAgIGZsb3cgKz0gYWRkZmxvdzsKICAgIH0KICAgIHJldHVybiB7Y29zdCxmbG93fTsKICB9Cn07
compilation info
prog.cpp:8:3: error: ‘vector’ does not name a type
vector<Edgee> g[mxN];
^~~~~~
prog.cpp:17:3: error: ‘pair’ does not name a type
pair<int, int> minCostMaxFlow() {
^~~~
prog.cpp: In member function ‘void MCMF::addEdge(int, int, int, int)’:
prog.cpp:13:35: error: ‘g’ was not declared in this scope
Edgee e1 = { v, cost, cap, 0, g[v].size() };
^
stdout