# HDOJ1733：Escape——网络流分层图

Problem Description
Loneknight hates attending class very much. Every time he is attending class, when he feel tiresome with the class, he start planning the shortest path he can escape from the classroom. Therefore, he can escape from classroom so quickly that he is always the first one escape from the classroom after the class finishes. He is very proud of this fact.

One day, loneknight is day dreaming in class, and planning the shortest path for escaping. Suddently, an issue come into his mind, if everyone in the classroom want to escape as soon as possible just as loneknight, what will happend? As a kind man, loneknight want to plan a strategy that will let everyone escape from the classroom with minimum time consume. But after dozens of minutes of consideration, loneknight find this problem so difficult for him.

Now, as the best friend of him, please design a algorithm to solve this problem for him. Note that, at every time unit, everyone can move seperately up, down, left, right one unit, or stay in the old position. In addtion, no one can move to a wall or out of the room, the only way to escape is go through a gate. Moreover, at every time unit, a position can only contain a person, including gates. That means if in time t, a person escape thourgh gate g, no one can go into g in time t, but can go into g in t + 1. Now, it’s your job to calculate the minimum time required to escape for everyone.

Input
The input consists of several test cases. Each test case start with a line containing two number, n, m (1

```#include
#include
#include

char mp[30][30];
const int inf=1=1&&x=1&&y0&&dis[x]==dis[y]+1)
{
int temp_flow=gfs(y,min(temp,c));
temp-=temp_flow;
edge[j].f-=temp_flow;
edge[j^1].f+=temp_flow;
if(temp==0||dis[s]==nn)
return flow-temp;
}
if(c>0&&pos>dis[y])
pos=dis[y];
}
if(temp==flow)
{
if(!(--gap[dis[x]]))
dis[s]=nn;
else
gap[dis[x]=pos+1]++;
}
return flow-temp;
}
int sap()
{
int maxflow=0;
memset(gap,0,sizeof(gap));
memset(dis,0,sizeof(dis));
gap[0]=nn;
while(dis[s]