include iostream include vector include cmath include set include map

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;
vector <vector <int>> g;
vector <bool> used;
vector <int> mt;
bool try_kunn(int v)
{
used[v] = true;
for (int i = 0; i < g[v].size(); i++)
{
int to = g[v][i];
}
}
int main()
{
int n, m;
cin >> n >> m;
vector <vector <int>> vec(n, vector <int>(m));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> vec[i][j];
}
}
int wcount = 0;
int bcount = 0;
map <pair<int, int>, int > s;
map <pair<int, int>, int > :: iterator it, got;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if ((i + j) % 2 == 0)
{
s[make_pair(i,j)] = bcount++;
}
else
{
s[make_pair(i, j)] = wcount++;
}
}
}
g.resize(s.size());
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if ((i + j) % 2 == 0)
{
if ((i - 1 >= 0) && vec[i - 1][j] != vec[i][j] )
g[s[make_pair(i, j)]].push_back(s[make_pair(i - 1, j)]);
if (j - 1 >= 0 && vec[i][j - 1] != vec[i][j] )
g[s[make_pair(i, j)]].push_back(s[make_pair(i , j -1)]);
if (i + 1 < n && vec[i + 1][j] != vec[i][j] )
g[s[make_pair(i, j)]].push_back(s[make_pair(i + 1, j)]);
if (j + 1 < m && vec[i][j + 1] != vec[i][j] )
g[s[make_pair(i, j)]].push_back(s[make_pair(i, j + 1)]);
}
}
}
return 0;
}