#include #include using namespace std; using ll = long long; using ld = long double; using mint = atcoder::modint1000000007; const ll inf = 9e18; struct UnionFind{ vector par; vector size; UnionFind(ll n){ par.resize(2*(n+1),-1); size.resize(2*(n+1),1); } ll root(ll x){ if (par[x]==-1) return x; return par[x]=root(par[x]); } void unite(ll u,ll v){ ll uu=root(u),vv=root(v); if(uu==vv){ return; } if(size[uu]> h >> w; vector a(h,vector(w)); for(ll i=0;i> a[i][j]; } } vector edge(h*w+1,vector>(0)); for(ll i=0;i> q; vector> sg(q); for(auto&[si,sj,gi,gj]:sg){ cin >> si >> sj >> gi >> gj; si--,sj--,gi--,gj--; } vector ok(q,h*w+2),ng(q,0); auto check=[&]()->bool { for(ll i=0;i1) return true; } return false; }; while(check()){ vector mid(h*w+1,vector(0)); for(ll i=0;i