constint MAX = 2e5+50; vector<int> es[MAX]; int n;
voiddfs(int u, int fa){ printf("%d ", u); for (auto& v: es[u]) { if (v == fa) continue; dfs(v, u); printf("%d ", u); } }
intmain(){ scanf("%d", &n); for (int i = 1; i < n; i++) { int u, v; scanf("%d%d", &u, &v); es[u].push_back(v); es[v].push_back(u); } for (int i = 1; i <= n; i++) sort(es[i].begin(), es[i].end()); dfs(1, 0); return0; }
constint MAX = 505; structEdge { int v, w, next; }es[MAX * MAX * 30]; int head[MAX * MAX], k, h, w; int d[MAX * MAX], id[MAX][MAX], idx; char s[MAX][MAX]; bool vis[MAX * MAX]; int f[4][2] = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };
voidadd(int u, int v, int w){ es[++k].next = head[u]; es[k].v = v; es[k].w = w; head[u] = k; }
intdij(){ memset(d, 0x3f, sizeof(d)); priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q; q.push(make_pair(0, 1)); d[1] = 0; while (q.size()) { int u = q.top().second; q.pop(); if (vis[u]) continue; vis[u] = true; for (int i = head[u]; i; i = es[i].next) { int v = es[i].v; if (!vis[v] && d[v] > d[u] + es[i].w) { d[v] = d[u] + es[i].w; q.push(make_pair(d[v], v)); } } } return d[id[h][w]]; }
intmain(){ scanf("%d%d", &h, &w); for (int i = 1; i <= h; i++) scanf("%s", s[i] + 1); for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { id[i][j] = ++idx; } } for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { for (int t = 0; t < 4; t++) { int nx = i + f[t][0]; int ny = j + f[t][1]; if (nx >= 1 && nx <= h && ny >= 1 && ny <= w) { if (s[nx][ny] == '.') add(id[i][j], id[nx][ny], 0); } } for (int x = -2; x <= 2; x++) { for (int y = -2; y <= 2; y++) { if (abs(x) == 2 && abs(y) == 2) continue; int nx = i + x, ny = j + y; if (nx >= 1 && nx <= h && ny >= 1 && ny <= w) { add(id[i][j], id[nx][ny], 1); } } } } } printf("%d\n", dij()); return0; }