Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n, m, k, x, y;
- bool p[12][12][12], visited[12][12][12];
- struct node {
- int k, x, y;
- node(int a, int b, int c) {
- k = a, x = b, y = c;
- }
- };
- int BFS() {
- queue <node> q;
- q.push(node(0, x, y));
- visited[0][x][y] = true;
- int res = 1;
- while (!q.empty()) {
- node top = q.front();
- q.pop();
- vector <node> adj;
- if (top.k < k - 1)
- adj.push_back(node(top.k + 1, top.x, top.y)); //down
- if (top.k > 0)
- adj.push_back(node(top.k - 1, top.x, top.y)); //up
- if (top.x < n - 1)
- adj.push_back(node(top.k, top.x + 1, top.y)); //right
- if (top.x > 0)
- adj.push_back(node(top.k, top.x - 1, top.y)); //left
- if (top.y < m - 1)
- adj.push_back(node(top.k, top.x, top.y + 1)); //forward
- if (top.y > 0)
- adj.push_back(node(top.k, top.y, top.y - 1)); //back
- for (int i = 0; i < adj.size(); i++) {
- if(!visited[adj[i].k][adj[i].x][adj[i].y] && p[adj[i].k][adj[i].x][adj[i].y]) {
- q.push(node(adj[i].k, adj[i].x, adj[i].y));
- visited[adj[i].k][adj[i].x][adj[i].y] = true;
- res++;
- }
- }
- }
- return res;
- }
- int main()
- {
- cin >> k >> n >> m;
- for (int c = 0; c < k; c++)
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++) {
- char x;
- cin >> x;
- if (x == '.')
- p[c][i][j] = true;
- }
- cin >> x >> y;
- x--, y--;
- cout << BFS();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement