[ad_1]
#embrace <bits/stdc++.h>
utilizing
namespace
std;
void
traverse(
int
i,
int
j,
int
N,
int
M,
vector<vector<
bool
> >& vis,
vector<vector<
bool
> >& row,
vector<vector<
bool
> >& col)
int
depend(
int
N,
int
M,
int
Okay,
vector<vector<
int
> >& q)
{
vector<vector<
bool
> > row(N + 1,
vector<
bool
>(
M + 1,
true
));
vector<vector<
bool
> > col(N + 1,
vector<
bool
>(
M + 1,
true
));
vector<vector<
bool
> > vis(N + 1,
vector<
bool
>(
M + 1,
false
));
for
(
int
i = 0; i < Okay; i++) {
if
(q[i][0] == q[i][2]) {
int
mn = min(q[i][1], q[i][3]);
row[q[i][0]][mn] =
false
;
}
else
{
int
mn = min(q[i][0], q[i][2]);
col[mn][q[i][1]] =
false
;
}
}
int
TotalRegion = 0;
for
(
int
i = 1; i <= N; i++) {
for
(
int
j = 1; j <= M; j++) {
if
(!vis[i][j]) {
TotalRegion++;
traverse(i, j, N, M,
vis, row, col);
}
}
}
return
TotalRegion;
}
int
essential()
{
vector<vector<
int
> > q;
int
N = 5, M = 5;
int
Okay = 10;
q.push_back({ 2, 1, 2, 2 });
q.push_back({ 1, 2, 2, 2 });
q.push_back({ 1, 3, 2, 3 });
q.push_back({ 1, 4, 2, 4 });
q.push_back({ 2, 3, 3, 3 });
q.push_back({ 3, 3, 3, 4 });
q.push_back({ 3, 3, 4, 3 });
q.push_back({ 3, 3, 3, 2 });
q.push_back({ 3, 1, 3, 2 });
q.push_back({ 4, 1, 4, 2 });
cout << depend(N, M, Okay, q);
return
0;
}
[ad_2]