intmain(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int N, M; std::cin >> N >> M;
std::map<std::pair<int, int>, bool> mp; std::vector<std::string> G(N); std::vector<std::vector<int>> vis(N, std::vector<int>(M)); int sum = 0; for (int i = 0; i < N; ++i) { std::cin >> G[i]; for (int j = 0; j < M; ++j) { if (G[i][j] == 'w') sum++; if (G[i][j] == 'c') { for (int a = -1; a <= 1; ++a) { for (int b = -1; b <= 1; ++b) { int x = a + i, y = b + j; if (x >= N || y >= M || x < 0 || y < 0) continue ; mp[{x, y}] = true; } } } } } for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { if (G[i][j] == 'm') { for (int a = -1; a <= 1; ++a) { for (int b = -1; b <= 1; ++b) { int x = a + i, y = b + j; if (x >= N || y >= M || x < 0 || y < 0) continue ; if (G[x][y] == 'w') { vis[x][y] = true; } } } } } }
std::vector<std::array<int, 2>> p; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { if (!vis[i][j] && G[i][j] == 'w') { for (int a = -1; a <= 1; ++a) { for (int b = -1; b <= 1; ++b) { int x = a + i, y = b + j; if (x >= N || y >= M || x < 0 || y < 0) continue ; if (G[x][y] == '.' && !mp.count({x, y})) { p.push_back({x, y}); } } } } } }
std::vector<std::array<int, 2>> ans; for (auto [x, y] : p) { auto work = [&](int a, int b) { std::vector<std::vector<int>> copy = vis; std::vector<std::pair<int, int>> now; for (int i = -1; i <= 1; ++i) { for (int j = -1; j <= 1; ++j) { int x = a + i, y = b + j; if (x >= N || y >= M || x < 0 || y < 0) continue ; if (G[x][y] == 'w' && !vis[x][y]) { vis[x][y] = true; now.push_back({x, y}); } } }
int res = 0; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { if (vis[i][j] && G[i][j] == 'w') { res++; } } }
if (res == sum) { ans.push_back({a, b}); } vis = copy; }; work(x, y); }
std::sort(ans.begin(), ans.end(), [&](auto i, auto j) { if (i[0] == j[0]) return i[1] < j[1]; return i[0] < j[0]; });
if (ans.empty()) { std::cout << "Too cold!\n"; return0; }
ans.erase(std::unique(ans.begin(), ans.end()), ans.end()); for (auto [x, y] : ans) { std::cout << x + 1 << " " << y + 1 << "\n"; }
std::string s; while (std::getline(std::cin, s)) { s += '&'; auto work = [&](std::string a, int n) { for (int i = 0; i < n; ++i) { int j = i; bool ok = false; while ((isalnum(a[j])) && j < n) { j++; ok = true; } if (ok) { vec.push_back(s.substr(i, j - i)); } i = j; } }; work(s, s.size()); }
intmain(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; std::cin >> n;
std::vector<int> a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; }
std::sort(a.begin(), a.end());
i64 sum = 0; std::vector<i64> b; do { int x = 0; for (int i = 0; i < n; i++) { x = x * 10 + a[i]; } b.push_back(1LL * x * x); sum += 1LL * x * x; } while (std::next_permutation(a.begin(), a.end())); int limit = (n == 3 ? 3 : 12);
std::vector<int> c; std::vector<int> vis(b.size() + 1); auto dfs = [&](auto self, int x, int cnt, std::vector<int> path, i64 s) -> bool { if (cnt == limit) { if (s == sum / 2) { c = path; returntrue; } } for (int i = x; i < b.size(); i++) { if (!vis[i]) { if (s + b[i] <= sum / 2) { vis[i] = true; path.push_back(sqrt(b[i])); self(self, x + 1, cnt + 1, path, s + b[i]); path.pop_back(); vis[i] = false; } } } returnfalse; }; dfs(dfs, 0, 0, c, 0);
intmain(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, m, s, t; std::cin >> n >> m >> s >> t;
std::vector<int> w(n + 1); for (int i = 1; i <= n; i++) { std::cin >> w[i]; }
w[s] = w[t] = 0; std::vector<std::vector<int>> G(1005, std::vector<int>(1005, inf)); for (int i = 0; i < m; i++) { int u, v, w; std::cin >> u >> v >> w;
G[u][v] = w; G[v][u] = w; }
std::vector<int> val(n + 1); std::vector<int> dist(n + 1, inf), vis(n + 1); auto dijkstra = [&]() { for (int i = 1; i <= n; i++) { dist[i] = G[s][i]; if (G[s][i] != inf) { val[i] = w[i]; } } vis[s] = true;
for (int i = 0; i + 1 < n; i++) { int t = -1; for (int j = 1; j <= n; j++) { if (!vis[j] && (t == -1 || dist[t] > dist[j])) t = j; }