思考
考虑搜索。
因为m <= 100000,所以直接硬搜索是不行的,用预处理解决问题
A能到B则B一定能到A,进一步,在A能到的连通块中的每个格子都能在这个区域里移动且只能在这个区域移动。
代码
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
int cur;
int a[1010][1010];
int col[1010][1010];
int num[1000010];
void dfs(int x,int y)
{
if(x < 1|| x > n || y < 1 || y > n) return;
if(col[x]