p:`A`B`C`D`E`f`g`h`i`j
t:((0;7 8);(1; 5 6 8);(2;(,) 5);(3;6 8 9);(4; 7 8)) // Caps preferences
// matrix conversion
// mm: ./[em:count[t[;0]]#(,)count[ppl]#0b;;:;1b] t
// flip[mm,em]|mm,em
// matching problem for bipariate graphs
mtch:{[P;x] $[null r:first where `=P p:v x; P:apath[P;x];P[p r]:x];P}
// swap augmenting paths (assuming it meets Hall's theorem conditions)
apath:{[P;x] sel:first (where max each v in v x) inter where max each v in opts:where P=`;
P[P?sel]:x;
P[first opts]:sel;P
}
v:(!). p flip t
R:(!). flip (p except key v),'`
q)v
A| `h`i
B| `f`g`i
C| ,`f
D| `g`i`j
E| `h`i
q)mtch/[R;key v]
f| C
g| B
h| A
i| E
j| D