<span style="font-size:18px;">#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a) memset(a,0,sizeof(a))
typedef long long ll;
typedef unsigned long long ULL;
const int mod = 1000000007;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const int big=50000;
int max(int a,int b) {return a>b?a:b;};
int min(int a,int b) {return a<b?a:b;};
int n,m,x,y;
vector<int> G[1005];
vector<int> dx,dy,px,py;
char field[15][15];
int xx[4]={-1,1,0,0},yy[4]={0,0,1,-1};
int sroad[15][15][15][15],dist[15][15];
int used[150],match[150];
void add_edge(int u,int v)
{
G[u].push_back(v);
G[v].push_back(u);
//printf("%d %d//////\n",u,G[u][G[u].size()-1]);
}
void bfs(int x,int y)
{
memset(dist,-1,sizeof(dist));
dist[x][y]=0;
queue<int> qx,qy;
qx.push(x);
qy.push(y);
while(!qx.empty())
{
for(int i=0;i<=3;i++)
{
int tx=qx.front()+xx[i],ty=qy.front()+yy[i];
if(tx>=1&&tx<=n&&ty>=1&&ty<=m)
{
if(field[tx][ty]=='.'&&dist[tx][ty]<0)
{
dist[tx][ty]=dist[x][y]+1;
sroad[x][y][tx][ty]=dist[tx][ty];
qx.push(tx);
qy.push(ty);
}
}
}
qx.pop();
qy.pop();
}
}
int dfs(int u)
{
used[u]=1;
for(int i=0;i<G[u].size();i++)
{
int v=G[u][i],w=match[v];
//printf("%d %d %d %d//////\n",u,match[u],v,match[v]);
if(w<0||!used[w]&&dfs(w))
{
match[u]=v;
match[v]=u;
return 1;
}
}
return 0;
}
int pipei(int t)
{
int res=0;
for(int i=0;i<dx.size();i++)
{
int u=i+t*dx.size();
//cout<<u<<" /////// "<<match[u]<<endl;
if(match[u]<0)
{
memset(used,0,sizeof(used));
if(dfs(u))
res++;
}
}
return res;
}
int num(int t)
{
for(int i=0;i<px.size();i++)
for(int j=0;j<dx.size();j++)
{
int renx=px[i],reny=py[i];
int menx=dx[j],meny=dy[j];
if(sroad[menx][meny][renx][reny]<=t)
add_edge(t*dx.size()+j,1000*dx.size()+i);
}
return pipei(t);
}
void solve()
{
memset(match,-1,sizeof(match));
memset(sroad,inf,sizeof(sroad));
int ans=0;
for(int t=0;t<=n*m+3;t++)
{
ans+=num(t);
if(ans>=px.size())
{
cout<<t<<endl;
return;
}
}
cout<<"impossible"<<endl;
}
int main()
{
int cas;
cin>>cas;
while(cas--)
{
scanf("%d %d",&n,&m);
dx.clear();dy.clear();
px.clear();py.clear();
for(int i=0;i<=500;i++)
G[i].clear();
for(int i=1;i<=n;i++)
scanf("%s",field[i]);
for(int i=1;i<=n;i++)
{
for(int j=0;j<m;j++)
if(field[i][j]=='D')
{
dx.push_back(i);
dy.push_back(j+1);
bfs(i,j+1);
}
else if(field[i][j]=='.')
{
px.push_back(i);
py.push_back(j+1);
}
}
solve();
}
return 0;
}
</span>
</pre><ul style="font-family: Simsun;font-size:14px;"><pre class="sh_cpp sh_sourceCode" style="font-family: 'Courier New', Courier, monospace; background-color: white;"><span class="sh_preproc" style="color: rgb(0, 0, 139); font-weight: bold;">#include</span> <span class="sh_string" style="color: red; font-family: monospace;"><iostream></span>
<span class="sh_preproc" style="color: rgb(0, 0, 139); font-weight: bold;">#include</span> <span class="sh_string" style="color: red; font-family: monospace;"><cstdio></span>
<span class="sh_preproc" style="color: rgb(0, 0, 139); font-weight: bold;">#include</span> <span class="sh_string" style="color: red; font-family: monospace;"><cstring></span>
<span class="sh_preproc" style="color: rgb(0, 0, 139); font-weight: bold;">#include</span> <span class="sh_string" style="color: red; font-family: monospace;"><cstdlib></span>
<span class="sh_preproc" style="color: rgb(0, 0, 139); font-weight: bold;">#include</span> <span class="sh_string" style="color: red; font-family: monospace;"><cmath></span>
<span class="sh_preproc" style="color: rgb(0, 0, 139); font-weight: bold;">#include</span> <span class="sh_string" style="color: red; font-family: monospace;"><vector></span>
<span class="sh_preproc" style="color: rgb(0, 0, 139); font-weight: bold;">#include</span> <span class="sh_string" style="color: red; font-family: monospace;"><queue></span>
<span class="sh_preproc" style="color: rgb(0, 0, 139); font-weight: bold;">#include</span> <span class="sh_string" style="color: red; font-family: monospace;"><map></span>
<span class="sh_preproc" style="color: rgb(0, 0, 139); font-weight: bold;">#include</span> <span class="sh_string" style="color: red; font-family: monospace;"><algorithm></span>
<span class="sh_preproc" style="color: rgb(0, 0, 139); font-weight: bold;">#include</span> <span class="sh_string" style="color: red; font-family: monospace;"><set></span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">using</span> <span class="sh_keyword" style="color: blue; font-weight: bold;">namespace</span> std<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_preproc" style="color: rgb(0, 0, 139); font-weight: bold;">#define</span> <span class="sh_function" style="font-weight: bold;">MM</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>a<span class="sh_symbol" style="color: rgb(139, 0, 0);">)</span> <span class="sh_function" style="font-weight: bold;">memset</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>a<span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span><span class="sh_keyword" style="color: blue; font-weight: bold;">sizeof</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>a<span class="sh_symbol" style="color: rgb(139, 0, 0);">))</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">typedef</span> <span class="sh_type" style="color: rgb(0, 100, 0);">long</span> <span class="sh_type" style="color: rgb(0, 100, 0);">long</span> ll<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">typedef</span> <span class="sh_type" style="color: rgb(0, 100, 0);">unsigned</span> <span class="sh_type" style="color: rgb(0, 100, 0);">long</span> <span class="sh_type" style="color: rgb(0, 100, 0);">long</span> ULL<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">const</span> <span class="sh_type" style="color: rgb(0, 100, 0);">int</span> mod <span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span> <span class="sh_number" style="color: purple;">1000000007</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">const</span> <span class="sh_type" style="color: rgb(0, 100, 0);">double</span> eps <span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span> <span class="sh_number" style="color: purple;">1e-10</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">const</span> <span class="sh_type" style="color: rgb(0, 100, 0);">int</span> inf <span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span> <span class="sh_number" style="color: purple;">0x3f3f3f3f</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">const</span> <span class="sh_type" style="color: rgb(0, 100, 0);">int</span> big<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span><span class="sh_number" style="color: purple;">50000</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> <span class="sh_function" style="font-weight: bold;">max</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> a<span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> b<span class="sh_symbol" style="color: rgb(139, 0, 0);">)</span> <span class="sh_cbracket" style="color: red;">{</span><span class="sh_keyword" style="color: blue; font-weight: bold;">return</span> a<span class="sh_symbol" style="color: rgb(139, 0, 0);">></span>b<span class="sh_symbol" style="color: rgb(139, 0, 0);">?</span>a<span class="sh_symbol" style="color: rgb(139, 0, 0);">:</span>b<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span><span class="sh_cbracket" style="color: red;">}</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> <span class="sh_function" style="font-weight: bold;">min</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> a<span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> b<span class="sh_symbol" style="color: rgb(139, 0, 0);">)</span> <span class="sh_cbracket" style="color: red;">{</span><span class="sh_keyword" style="color: blue; font-weight: bold;">return</span> a<span class="sh_symbol" style="color: rgb(139, 0, 0);"><</span>b<span class="sh_symbol" style="color: rgb(139, 0, 0);">?</span>a<span class="sh_symbol" style="color: rgb(139, 0, 0);">:</span>b<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span><span class="sh_cbracket" style="color: red;">}</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> n<span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span>m<span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span>x<span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span>y<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
vector<span class="sh_symbol" style="color: rgb(139, 0, 0);"><</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">></span> G<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span><span class="sh_number" style="color: purple;">100005</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">];</span>
vector<span class="sh_symbol" style="color: rgb(139, 0, 0);"><</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">></span> dx<span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span>dy<span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span>px<span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span>py<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">char</span> field<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span><span class="sh_number" style="color: purple;">15</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span><span class="sh_number" style="color: purple;">15</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">];</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> xx<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span><span class="sh_number" style="color: purple;">4</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">]=</span><span class="sh_cbracket" style="color: red;">{</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">-</span><span class="sh_number" style="color: purple;">1</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span><span class="sh_number" style="color: purple;">1</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span><span class="sh_number" style="color: purple;">0</span><span class="sh_cbracket" style="color: red;">}</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span>yy<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span><span class="sh_number" style="color: purple;">4</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">]=</span><span class="sh_cbracket" style="color: red;">{</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span><span class="sh_number" style="color: purple;">1</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">,-</span><span class="sh_number" style="color: purple;">1</span><span class="sh_cbracket" style="color: red;">}</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> sroad<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span><span class="sh_number" style="color: purple;">15</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span><span class="sh_number" style="color: purple;">15</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span><span class="sh_number" style="color: purple;">15</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span><span class="sh_number" style="color: purple;">15</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">],</span>dist<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span><span class="sh_number" style="color: purple;">15</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span><span class="sh_number" style="color: purple;">15</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">];</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> used<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span><span class="sh_number" style="color: purple;">30000</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">],</span>match<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span><span class="sh_number" style="color: purple;">1000000</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">];</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">void</span> <span class="sh_function" style="font-weight: bold;">add_edge</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> u<span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> v<span class="sh_symbol" style="color: rgb(139, 0, 0);">)</span>
<span class="sh_cbracket" style="color: red;">{</span>
G<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>u<span class="sh_symbol" style="color: rgb(139, 0, 0);">].</span><span class="sh_function" style="font-weight: bold;">push_back</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>v<span class="sh_symbol" style="color: rgb(139, 0, 0);">);</span>
G<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>v<span class="sh_symbol" style="color: rgb(139, 0, 0);">].</span><span class="sh_function" style="font-weight: bold;">push_back</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>u<span class="sh_symbol" style="color: rgb(139, 0, 0);">);</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">void</span> <span class="sh_function" style="font-weight: bold;">bfs</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> x<span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> y<span class="sh_symbol" style="color: rgb(139, 0, 0);">)</span>
<span class="sh_cbracket" style="color: red;">{</span>
<span class="sh_function" style="font-weight: bold;">memset</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>dist<span class="sh_symbol" style="color: rgb(139, 0, 0);">,-</span><span class="sh_number" style="color: purple;">1</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span><span class="sh_keyword" style="color: blue; font-weight: bold;">sizeof</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>dist<span class="sh_symbol" style="color: rgb(139, 0, 0);">));</span>
dist<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>x<span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span>y<span class="sh_symbol" style="color: rgb(139, 0, 0);">]=</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
queue<span class="sh_symbol" style="color: rgb(139, 0, 0);"><</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">></span> qx<span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span>qy<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
qx<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">push</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>x<span class="sh_symbol" style="color: rgb(139, 0, 0);">);</span>
qy<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">push</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>y<span class="sh_symbol" style="color: rgb(139, 0, 0);">);</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">while</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(!</span>qx<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">empty</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">())</span>
<span class="sh_cbracket" style="color: red;">{</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> sx<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span>qx<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">front</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">();</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> sy<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span>qy<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">front</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">();</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">for</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> i<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);"><=</span><span class="sh_number" style="color: purple;">3</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">++)</span>
<span class="sh_cbracket" style="color: red;">{</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> tx<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span>sx<span class="sh_symbol" style="color: rgb(139, 0, 0);">+</span>xx<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">],</span>ty<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span>sy<span class="sh_symbol" style="color: rgb(139, 0, 0);">+</span>yy<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">];</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">if</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>tx<span class="sh_symbol" style="color: rgb(139, 0, 0);">>=</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">&&</span>tx<span class="sh_symbol" style="color: rgb(139, 0, 0);"><</span>n<span class="sh_symbol" style="color: rgb(139, 0, 0);">&&</span>ty<span class="sh_symbol" style="color: rgb(139, 0, 0);">>=</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">&&</span>ty<span class="sh_symbol" style="color: rgb(139, 0, 0);"><</span>m<span class="sh_symbol" style="color: rgb(139, 0, 0);">)</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">if</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>field<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>tx<span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span>ty<span class="sh_symbol" style="color: rgb(139, 0, 0);">]==</span><span class="sh_string" style="color: red; font-family: monospace;">'.'</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">&&</span>dist<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>tx<span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span>ty<span class="sh_symbol" style="color: rgb(139, 0, 0);">]<</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">)</span>
<span class="sh_cbracket" style="color: red;">{</span>
dist<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>tx<span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span>ty<span class="sh_symbol" style="color: rgb(139, 0, 0);">]=</span>dist<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>sx<span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span>sy<span class="sh_symbol" style="color: rgb(139, 0, 0);">]+</span><span class="sh_number" style="color: purple;">1</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
sroad<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>x<span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span>y<span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span>tx<span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span>ty<span class="sh_symbol" style="color: rgb(139, 0, 0);">]=</span>dist<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>tx<span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span>ty<span class="sh_symbol" style="color: rgb(139, 0, 0);">];</span>
qx<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">push</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>tx<span class="sh_symbol" style="color: rgb(139, 0, 0);">);</span>
qy<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">push</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>ty<span class="sh_symbol" style="color: rgb(139, 0, 0);">);</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_cbracket" style="color: red;">}</span>
qx<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">pop</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">();</span>
qy<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">pop</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">();</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> <span class="sh_function" style="font-weight: bold;">dfs</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> u<span class="sh_symbol" style="color: rgb(139, 0, 0);">)</span>
<span class="sh_cbracket" style="color: red;">{</span>
used<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>u<span class="sh_symbol" style="color: rgb(139, 0, 0);">]=</span><span class="sh_number" style="color: purple;">1</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">for</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> i<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);"><</span>G<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>u<span class="sh_symbol" style="color: rgb(139, 0, 0);">].</span><span class="sh_function" style="font-weight: bold;">size</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">();</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">++)</span>
<span class="sh_cbracket" style="color: red;">{</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> v<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span>G<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>u<span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">],</span>w<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span>match<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>v<span class="sh_symbol" style="color: rgb(139, 0, 0);">];</span>
<span class="sh_comment" style="color: rgb(165, 42, 42); font-style: italic;">//printf("%d %d\n",v,match[v]);</span>
<span class="sh_comment" style="color: rgb(165, 42, 42); font-style: italic;">// printf("match: %d w:%d\n",match[v],w);</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">if</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>w<span class="sh_symbol" style="color: rgb(139, 0, 0);"><</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">||!</span>used<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>w<span class="sh_symbol" style="color: rgb(139, 0, 0);">]&&</span><span class="sh_function" style="font-weight: bold;">dfs</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>w<span class="sh_symbol" style="color: rgb(139, 0, 0);">))</span>
<span class="sh_cbracket" style="color: red;">{</span>
match<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>u<span class="sh_symbol" style="color: rgb(139, 0, 0);">]=</span>v<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
match<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>v<span class="sh_symbol" style="color: rgb(139, 0, 0);">]=</span>u<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_comment" style="color: rgb(165, 42, 42); font-style: italic;">//printf("wwwww\n");</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">return</span> <span class="sh_number" style="color: purple;">1</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">return</span> <span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> <span class="sh_function" style="font-weight: bold;">pipei</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> t<span class="sh_symbol" style="color: rgb(139, 0, 0);">)</span>
<span class="sh_cbracket" style="color: red;">{</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> res<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">for</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> i<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);"><</span>dx<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">size</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">();</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">++)</span>
<span class="sh_cbracket" style="color: red;">{</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> u<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">+</span>t<span class="sh_symbol" style="color: rgb(139, 0, 0);">*</span>dx<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">size</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">();</span>
<span class="sh_comment" style="color: rgb(165, 42, 42); font-style: italic;">//printf("4 match:%d\n",match[0]);</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">if</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>match<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>u<span class="sh_symbol" style="color: rgb(139, 0, 0);">]<</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">)</span>
<span class="sh_cbracket" style="color: red;">{</span>
<span class="sh_function" style="font-weight: bold;">memset</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>used<span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span><span class="sh_keyword" style="color: blue; font-weight: bold;">sizeof</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>used<span class="sh_symbol" style="color: rgb(139, 0, 0);">));</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">if</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_function" style="font-weight: bold;">dfs</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>u<span class="sh_symbol" style="color: rgb(139, 0, 0);">))</span>
res<span class="sh_symbol" style="color: rgb(139, 0, 0);">++;</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_comment" style="color: rgb(165, 42, 42); font-style: italic;">// printf("res:%d\n",res);</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">return</span> res<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> <span class="sh_function" style="font-weight: bold;">num</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> t<span class="sh_symbol" style="color: rgb(139, 0, 0);">)</span>
<span class="sh_cbracket" style="color: red;">{</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">for</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> i<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);"><</span>px<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">size</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">();</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">++)</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">for</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> j<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>j<span class="sh_symbol" style="color: rgb(139, 0, 0);"><</span>dx<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">size</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">();</span>j<span class="sh_symbol" style="color: rgb(139, 0, 0);">++)</span>
<span class="sh_cbracket" style="color: red;">{</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> renx<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span>px<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">],</span>reny<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span>py<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">];</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> menx<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span>dx<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>j<span class="sh_symbol" style="color: rgb(139, 0, 0);">],</span>meny<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span>dy<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>j<span class="sh_symbol" style="color: rgb(139, 0, 0);">];</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">if</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>sroad<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>menx<span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span>meny<span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span>renx<span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span>reny<span class="sh_symbol" style="color: rgb(139, 0, 0);">]<=</span>t<span class="sh_symbol" style="color: rgb(139, 0, 0);">)</span>
<span class="sh_function" style="font-weight: bold;">add_edge</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>t<span class="sh_symbol" style="color: rgb(139, 0, 0);">*</span>dx<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">size</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">()+</span>j<span class="sh_symbol" style="color: rgb(139, 0, 0);">,(</span>n<span class="sh_symbol" style="color: rgb(139, 0, 0);">*</span>m<span class="sh_number" style="color: purple;">+10</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">)*</span>dx<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">size</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">()+</span><span class="sh_number" style="color: purple;">10</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">+</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">);</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_comment" style="color: rgb(165, 42, 42); font-style: italic;">//printf("3 match:%d\n",match[0]);</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">return</span> <span class="sh_function" style="font-weight: bold;">pipei</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>t<span class="sh_symbol" style="color: rgb(139, 0, 0);">);</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">void</span> <span class="sh_function" style="font-weight: bold;">solve</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">()</span>
<span class="sh_cbracket" style="color: red;">{</span>
<span class="sh_function" style="font-weight: bold;">memset</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>match<span class="sh_symbol" style="color: rgb(139, 0, 0);">,-</span><span class="sh_number" style="color: purple;">1</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span><span class="sh_keyword" style="color: blue; font-weight: bold;">sizeof</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>match<span class="sh_symbol" style="color: rgb(139, 0, 0);">));</span>
<span class="sh_comment" style="color: rgb(165, 42, 42); font-style: italic;">//printf("1 match:%d\n",match[0]);</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> ans<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">for</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> t<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>t<span class="sh_symbol" style="color: rgb(139, 0, 0);"><=</span>n<span class="sh_symbol" style="color: rgb(139, 0, 0);">*</span>m<span class="sh_number" style="color: purple;">+3</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>t<span class="sh_symbol" style="color: rgb(139, 0, 0);">++)</span>
<span class="sh_cbracket" style="color: red;">{</span>
ans<span class="sh_symbol" style="color: rgb(139, 0, 0);">+=</span><span class="sh_function" style="font-weight: bold;">num</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>t<span class="sh_symbol" style="color: rgb(139, 0, 0);">);</span>
<span class="sh_comment" style="color: rgb(165, 42, 42); font-style: italic;">//cout<<t<<" "<<num(t)<<endl;</span>
<span class="sh_comment" style="color: rgb(165, 42, 42); font-style: italic;">//printf("2 match:%d\n",match[0]);</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">if</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>ans<span class="sh_symbol" style="color: rgb(139, 0, 0);">>=</span>px<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">size</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">())</span>
<span class="sh_cbracket" style="color: red;">{</span>
cout<span class="sh_symbol" style="color: rgb(139, 0, 0);"><<</span>t<span class="sh_symbol" style="color: rgb(139, 0, 0);"><<</span>endl<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">return</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_cbracket" style="color: red;">}</span>
cout<span class="sh_symbol" style="color: rgb(139, 0, 0);"><<</span><span class="sh_string" style="color: red; font-family: monospace;">"impossible"</span><span class="sh_symbol" style="color: rgb(139, 0, 0);"><<</span>endl<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> <span class="sh_function" style="font-weight: bold;">main</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">()</span>
<span class="sh_cbracket" style="color: red;">{</span>
<span class="sh_type" style="color: rgb(0, 100, 0);">int</span> cas<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
cin<span class="sh_symbol" style="color: rgb(139, 0, 0);">>></span>cas<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">while</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>cas<span class="sh_symbol" style="color: rgb(139, 0, 0);">--)</span>
<span class="sh_cbracket" style="color: red;">{</span>
<span class="sh_function" style="font-weight: bold;">scanf</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_string" style="color: red; font-family: monospace;">"%d %d"</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">,&</span>n<span class="sh_symbol" style="color: rgb(139, 0, 0);">,&</span>m<span class="sh_symbol" style="color: rgb(139, 0, 0);">);</span>
dx<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">clear</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">();</span>dy<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">clear</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">();</span>
px<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">clear</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">();</span>py<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">clear</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">();</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">for</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> i<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);"><=</span><span class="sh_number" style="color: purple;">500</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">++)</span>
G<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">].</span><span class="sh_function" style="font-weight: bold;">clear</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">();</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">for</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> i<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);"><</span>n<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">++)</span>
<span class="sh_function" style="font-weight: bold;">scanf</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_string" style="color: red; font-family: monospace;">"%s"</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span>field<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">]);</span>
<span class="sh_function" style="font-weight: bold;">memset</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>sroad<span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span>inf<span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span><span class="sh_keyword" style="color: blue; font-weight: bold;">sizeof</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>sroad<span class="sh_symbol" style="color: rgb(139, 0, 0);">));</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">for</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> i<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);"><</span>n<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">++)</span>
<span class="sh_cbracket" style="color: red;">{</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">for</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span><span class="sh_type" style="color: rgb(0, 100, 0);">int</span> j<span class="sh_symbol" style="color: rgb(139, 0, 0);">=</span><span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>j<span class="sh_symbol" style="color: rgb(139, 0, 0);"><</span>m<span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>j<span class="sh_symbol" style="color: rgb(139, 0, 0);">++)</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">if</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>field<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span>j<span class="sh_symbol" style="color: rgb(139, 0, 0);">]==</span><span class="sh_string" style="color: red; font-family: monospace;">'D'</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">)</span>
<span class="sh_cbracket" style="color: red;">{</span>
dx<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">push_back</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">);</span>
dy<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">push_back</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>j<span class="sh_symbol" style="color: rgb(139, 0, 0);">);</span>
<span class="sh_function" style="font-weight: bold;">bfs</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">,</span>j<span class="sh_symbol" style="color: rgb(139, 0, 0);">);</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">else</span> <span class="sh_keyword" style="color: blue; font-weight: bold;">if</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>field<span class="sh_symbol" style="color: rgb(139, 0, 0);">[</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">][</span>j<span class="sh_symbol" style="color: rgb(139, 0, 0);">]==</span><span class="sh_string" style="color: red; font-family: monospace;">'.'</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">)</span>
<span class="sh_cbracket" style="color: red;">{</span>
px<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">push_back</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>i<span class="sh_symbol" style="color: rgb(139, 0, 0);">);</span>
py<span class="sh_symbol" style="color: rgb(139, 0, 0);">.</span><span class="sh_function" style="font-weight: bold;">push_back</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">(</span>j<span class="sh_symbol" style="color: rgb(139, 0, 0);">);</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_function" style="font-weight: bold;">solve</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">();</span>
<span class="sh_cbracket" style="color: red;">}</span>
<span class="sh_keyword" style="color: blue; font-weight: bold;">return</span> <span class="sh_number" style="color: purple;">0</span><span class="sh_symbol" style="color: rgb(139, 0, 0);">;</span>
<span class="sh_cbracket" style="color: red;">}</span>

Poj 3057 未AC http://poj.org/showsource?solution_id=15175171的更多相关文章

  1. Poj 1755Triathlon 未Ac,先mark

    地址:http://poj.org/problem?id=1755 题目: Triathlon Time Limit: 1000MS   Memory Limit: 10000K Total Subm ...

  2. 九度OJ 1016 火星A + B 未AC版,整型存储不下

    #include <iostream> #include <string.h> #include <sstream> #include <math.h> ...

  3. poj 3057(bfs+二分匹配)

    题目链接:http://poj.org/problem?id=3057 题目大概意思是有一块区域组成的房间,房间的边缘有门和墙壁,'X'代表墙壁,'D'代表门,房间内部的' . '代表空区域,每个空区 ...

  4. poj 2278 DNASequnce AC自动机

    地址:http://poj.org/problem?id=2778 题目: DNA Sequence Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  5. POJ 1625 Censored!(AC自动机+DP+高精度)

    Censored! Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 6956   Accepted: 1887 Descrip ...

  6. POJ 3057 Evacuation 二分+最大流

    Evacuation 题目连接: http://poj.org/problem?id=3057 Description Fires can be disastrous, especially when ...

  7. POJ 3057 Evacuation(二分图匹配+BFS)

    [题目链接] http://poj.org/problem?id=3057 [题目大意] 给出一个迷宫,D表示门,.表示人,X表示不可通行, 每个门每时间单位只允许一个人通过, 每个人移动一格的为一时 ...

  8. 【最大匹配+二分答案】POJ 3057 Evacuation

    题目大意 POJ链接 有一个\(X×Y\)的房间,X代表墙壁,D是门,.代表人.这个房间着火了,人要跑出去,但是每一个时间点只有一个人可以从门出去. 问最后一个人逃出去的最短时间,如果不能逃出去,输出 ...

  9. poj 1625 (AC自动机好模版,大数好模版)

    题目 给n个字母,构成长度为m的串,总共有n^m种.给p个字符串,问n^m种字符串中不包含(不是子串)这p个字符串的个数. 将p个不能包含的字符串建立AC自动机,每个结点用val值来标记以当前节点为后 ...

随机推荐

  1. [转帖]U盘安装centos 的方法

    通过U盘或CD/DVD装centos7,出现“dracut-initqueue timeout..."解决办法   1.在用CD/DVD挂载centos7镜像安装系统时,出现“dracut- ...

  2. NoSQL数据库简介与产生

    关系型数据库所存在“问题” >利用ACID原则(原子性,一致性,隔离性,持久性)保证数据完整性: >行列的规范化存储: >预定义结构: >存储数据量“小”: >结构化查询 ...

  3. 为什么要学习Hive

    一 为什么要学习HIVE?   为什么不是ORACLE和MYSQL?   因为大数据时代 数据量成几何倍数增长,并且数据量非常庞大.大到要用PB EB这种量级去衡量.而我们的ORACLE/MYQL这种 ...

  4. 2-SAT问题介绍求解 + 模板题P4782

    (点击此处查看原题) 什么是2-SAT问题 sat 即 Satisfiability,意思为可满足,那么2-SAT表示一些布尔变量只能取true或者false,而某两个变量之间的值存在一定的关系(如: ...

  5. Python_4day

    函数 函数可以用来定义可重复代码,组织和简化 一般来说一个函数在实际开发中为一个小功能 一个类为一个大功能 同样函数的长度不要超过一屏   Python中的所有函数实际上都是有返回值(return N ...

  6. 转载:mysql数据库连接自动断开

    转自:https://www.cnblogs.com/ay-a/p/10520425.html MySql连接空闲8小时自动断开引起的问题   一.问题描述 ​ 最近遇到了一个奇怪的MySql数据库问 ...

  7. 直通BAT必考题系列:JVM性能调优的6大步骤,及关键调优参数详解

    JVM内存调优 对JVM内存的系统级的调优主要的目的是减少GC的频率和Full GC的次数. 1.Full GC 会对整个堆进行整理,包括Young.Tenured和Perm.Full GC因为需要对 ...

  8. openstack云主机冷迁移

    1:开启nova计算节点之间互信 冷迁移需要nova计算节点之间使用nova用户互相免密码访问 默认nova用户禁止登陆,开启所有计算节点的nova用户登录shell. usermod -s /bin ...

  9. Linux配置iSCSI存储

    1.基础知识 1.1 存储相关     直接存储(DAS):例如本机上的磁盘,就是属于直接存储设备.     存储区域网络(SAN):来自网络内的其他存储设备提供的磁盘.Iscsi就是属于该方式.   ...

  10. 关于Linux单机、集群部署FastDFS分布式文件系统的步骤。

    集群部署:2台tarcker服务器,2台storage服务器. 192.168.201.86   ---------(trackerd+storage+nginx) 192.168.201.87   ...