思路:
这道题要从男孩和女孩同时开始bfs,如果男孩走过女孩走过的点,那么就输出时间,女孩同理
当前格子能不能走只需要判断鬼的哈密顿距离是否能到达就行了
详见代码(其实就一个注释)
c o d e code code
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cmath>
using namespace std;
int t;
struct node
{
int x, y, s;
};
int n, m, g1x, g1y, g2x, g2y, flag;
char a[1000][1000];
queue<node> f, q;
int v[1000][1000];
int dx[4]={
0, 1, 0, -1};
int dy[4]={
1, 0, -1, 0};
inline int read() {
int x=0, f=1;
char s=getchar();
while (s<'0'||s>'9')
{
if(s=='-')
f=-f;
s=getchar();
}
while(s>='0'&&s<='9')
{
x=x*10+s-'0';
s=getchar();