题目链接:点击跳转
这题dfs和bfs都可以解决,这里就结合一下,把问题转化为网络流,用dinic算法解决。
对于每个非*的点,都向四周所能到达的地方建一条流量为1的边,如果最后T点有流量能到达,则说明S能到达T点。
代码如下:
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int MAXN = 5e3 + 5e2;
const int INF = 0x3f3f3f3f;
#define endl '\n'
inline void IO_STREAM() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
struct Edge{
int to,val,nxt;
}e[MAXN];
int head[MAXN], deep[MAXN], to[4][2] = {
1, 0, -1, 0, 0, 1, 0, -1};
int n, m, s, t, cnt;
ll res;
char gra[25][25];
inline void init() {
memset(head, -1, sizeof(head)