#include "../../common.cpp" #include #include // Graph Type with nested interior edge properties for flow algorithms typedef boost::adjacency_list_traits traits; typedef boost::adjacency_list>>> graph; typedef traits::vertex_descriptor vertex_desc; typedef traits::edge_descriptor edge_desc; class edge_adder { graph &G; public: explicit edge_adder(graph &G) : G(G) {} void add_edge(int from, int to, int capacity) { auto c_map = boost::get(boost::edge_capacity, G); auto r_map = boost::get(boost::edge_reverse, G); const auto e = boost::add_edge(from, to, G).first; const auto rev_e = boost::add_edge(to, from, G).first; c_map[e] = capacity; c_map[rev_e] = 0; // reverse edge has no capacity! r_map[e] = rev_e; r_map[rev_e] = e; } }; int main(){ setup(); auto t = read1(); while(0 < t--){ auto h = read1(); auto w = read1(); auto note = read1(); int n = note.size(); graph G(2+n+h*w); edge_adder adder(G); int counter = 2; // Edge to target for(int i=0; i(); for(int j=0; j(); for(int j=0; j