#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int minDist(const vector& plane, char wall, int y1, int x1, int y2, int x2) { int dy[] = {0, 0, -1, 1}; int dx[] = {-1, 1, 0, 0}; int h = plane.size(); int w = plane[0].size(); queue > q; vector > check(h, vector(w, false)); q.push(make_pair(y1, x1)); check[y1][x1] = true; int ret = 0; while(!q.empty()){ queue > q1; while(!q.empty()){ int y = q.front().first; int x = q.front().second; q.pop(); if(y == y2 && x == x2) return ret; for(int i=0; i<4; ++i){ int y0 = y + dy[i]; int x0 = x + dx[i]; if(0 <= y0 && y0 < h && 0 <= x0 && x0 < w && plane[y0][x0] != wall && !check[y0][x0]){ q1.push(make_pair(y0, x0)); check[y0][x0] = true; } } } ++ ret; q = q1; } return -1; } int main() { int w, h, n; cin >> w >> h >> n; vector s(2*h+1, string(2*w+1, '#')); for(int y=0; y > a(2*h+1, vector(2*w+1, 0)); vector > b(2*h+1, vector(2*w+1, 0)); for(int i=0; i> m; vector y(m+1), x(m+1); for(int j=0; j> b; y[j] = b / w; x[j] = b % w; } for(int j=1; j 0) s[y][x] = '.'; } } for(int x=0; x<2*w+1; ++x){ int sum = 0; for(int y=0; y<2*h+1; ++y){ sum += b[y][x]; if(sum > 0) s[y][x] = '.'; } } int ans = minDist(s, '#', 1, 1, 2 * h - 1, 2 * w - 1); if(ans == -1) cout << "Odekakedekinai.." << endl; else cout << (ans / 2) << endl; return 0; }