<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. pycharm 快捷键练习 和基本英语单词练习

    通过练习 一下快捷键 打代码的速度得到提升 pycharm以下 快捷键+快捷键意义 ctrl+a 全选 ctrl+c 复制(不选中默认复制一行) ctrl+v 粘贴 ctrl+x 剪切 ctrl+f ...

  2. SpringBoot 的启动banner生成网址

    1.http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Type%20Something%20 2.http://www. ...

  3. [转载]汇编语言assume伪指令的作用

    原文:https://blog.csdn.net/u010234808/article/details/38366943 摘出关键部分: 编写程序,是写给编译软件的.由编译软件,编译成机器码,再去控制 ...

  4. day3-3种实现小图标与文字水平对齐的方式

    效果图: 1.使用小图标作为背景图实现 html: <div class="test"> <ul> <li class="method1&q ...

  5. Exited too quickly (process log may have details)-配置问题

    在配置supervisor的时候,提示Exited too quickly (process log may have details),这个时候一脸懵逼,啥回事,执行太快了???

  6. CentOS7搭建FastDFS V5.11分布式文件系统(一)

    1.绪论 最近要用到fastDFS,所以自己研究了一下,在搭建FastDFS的过程中遇到过很多的问题,为了能帮忙到以后搭建FastDFS的同学,少走弯路,与大家分享一下.FastDFS的作者淘宝资深架 ...

  7. Beacon

    1.Beacon技术指的是通过使用低功耗蓝牙技术(Bluetooth Low Energy,也就是Bluetooth 4.0或者Bluetooth Smart),Beacon基站便可以自动创建一个信号 ...

  8. 08 自学Aruba之限制应用流量

    点击返回:自学Aruba之路点击返回:自学Aruba集锦 08 自学Aruba之限制应用流量 限制带宽请查阅:点击 下文描述的步骤,主要是针对某一个SSID所用用户在使用某一个应用的时候设置共享带宽. ...

  9. php页面加载完毕后再显示购买按钮

    php页面加载完毕后再显示购买按钮 $document.ready(function(){ $("#buybotton").show()})

  10. shell更改xml中的指定值

    sed -i 's;<id>.*<\/id>;<id>新内容<\/id>;g'  your.xml