View difference between Paste ID: W1h4PaMq and EwYkxGce
SHOW: | | - or go back to the newest paste.
1
#include <bits/stdc++.h>
2
3
using namespace std;
4
#define endl '\n'
5
6
vector<bool> odwiedz;
7
vector<vector<int> > G;
8
void DFS(int v)
9
{
10
    odwiedz[v] = true;
11
    for(int i = 0; i < G[v].size(); ++i)
12
    {
13
        int u = G[v][i];
14
        if(!odwiedz[u])
15
            DFS(u);
16
    }
17
}
18
bool czyistnieje(int v, int n)
19
{
20
    return 0 <= x && x < n && 0 <= y && y < m;
21
}
22
23
VPII sasiedzi = {
24
    {-1, -1},
25
    {-1, 0},
26
    {-1, 1},
27
    {0, -1},
28
    {0, 1},
29
    {1, -1},
30
    {1, 0},
31
    {1, 1}
32
};
33
34
int main()
35
{
36
    ios_base::sync_with_stdio(0);
37
    cin.tie(0);
38
39
    int n;
40
    cin >> n;
41
    vector<vector<int> > w(n, vector<int> (n));
42
    G.resize(n * n);
43
    odwiedz.resize(n * n);
44
    for(int  i = 0; i < n; ++i)
45
        for(int j = 0; j < n; ++j)
46
            cin >> w[i][j];
47
    for(int x = 0; x < n; ++x)
48
        for(int y = 0; y < n; ++y)
49
            for(PII &p : sasiedzi)
50
                if(czyistnieje(x + p.ST, y + p.ND))
51
                    G[nr(x, y)].emplace_back(nr(x + p.ST, y + p.ND));
52
    return 0;
53
}