#include #include #include #include #include typedef std::vector > graph; bool bfs(const graph &g, int s, int t, std::vector &parent) { int V = g.size(); std::vector visited(V); std::deque q; q.push_back(s); visited[s] = true; parent[s] = -1; while (!q.empty()) { int u = q.front(); q.pop_front(); for (auto it : g[u]) { int v = it.first; if (visited[v] == false && it.second > 0) { if (v == t) { parent[v] = u; return true; } q.push_back(v); parent[v] = u; visited[v] = true; } } } return false; } int fordFulkerson(const graph &g, int s, int t) { graph rg = g; int V = g.size(); std::vector parent(V); int max_flow = 0; while (bfs(rg, s, t, parent)) { int path_flow = std::numeric_limits::max(); for (int v = t; v != s; v = parent[v]) { int u = parent[v]; path_flow = std::min(path_flow, rg[u][v]); } for (int v = t; v != s; v = parent[v]) { int u = parent[v]; rg[u][v] -= path_flow; rg[v][u] += path_flow; } max_flow += path_flow; } return max_flow; } int main() { int h, w, t; std::cin >> h >> w >> t; std::vector grid(h*w); for(int i=0; i> grid[i]; graph g(2*h*w*(t+1)+2); int people = 0; for(int i=0; i= 0 && nbi < h && nbj >= 0 && nbj < w) { if(grid[nbi*w+nbj] != '#') { for(int x=0; x