Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin ("traseu.in");
- ofstream fout ("traseu.out");
- int a[105][105][105];
- short N, M, niv_start, lin_start, col_start, niv_stop, lin_stop, col_stop, x, y, z;
- const short dniv[] = {1, 0, 0, 0, 0, -1}, dlin[] = {0, 1, 0, 0, -1, 0}, dcol[] = {0, 0, 1, -1, 0, 0};
- vector < tuple < short , short , short > > sol;
- void Read () {
- fin >> N >> M;
- fin >> niv_start >> lin_start >> col_start >> niv_stop >> lin_stop >> col_stop;
- while (M --) {
- fin >> x >> y >> z;
- a[x][y][z] = -1;
- }
- }
- void Border () {
- for (short i = 0; i <= N + 1; i ++)
- for (short j = 0; j <= N + 1; j ++)
- a[0][i][j] = a[N + 1][i][j] = a[i][j][0] = a[i][j][N + 1] = a[i][0][j] = a[i][N + 1][j] = -1;
- }
- void Lee () {
- queue < tuple < short , short , short > > Q;
- Q.push (tie (niv_start , lin_start , col_start));
- a[niv_start][lin_start][col_start] = 1;
- while (a[niv_stop][lin_stop][col_stop] == 0) {
- tie(x, y, z) = Q.front();
- Q.pop();
- for (short k = 0; k < 6; k ++) {
- short xv = x + dniv[k], yv = y + dlin[k], zv = z + dcol[k];
- if (a[xv][yv][zv] == 0) {
- a[xv][yv][zv] = a[x][y][z] + 1;
- Q.push (tie (xv, yv, zv));
- }
- }
- }
- }
- int main () {
- Read ();
- Border ();
- Lee ();
- fout << a[niv_stop][lin_stop][col_stop] << '\n';
- sol.push_back (tie (niv_stop , lin_stop , col_stop));
- while (a[niv_stop][lin_stop][col_stop] > 1) {
- for (short k = 0; k < 6; k ++) {
- short xv = niv_stop - dniv[k], yv = lin_stop - dlin[k], zv = col_stop - dcol[k];
- if (a[xv][yv][zv] == a[niv_stop][lin_stop][col_stop] - 1) {
- niv_stop = xv, lin_stop = yv, col_stop = zv;
- break;
- }
- }
- sol.push_back (tie (niv_stop , lin_stop , col_stop));
- }
- reverse (sol.begin(), sol.end());
- for (auto it : sol) {
- tie (x, y, z) = it;
- fout << x << ' ' << y << ' ' << z << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment