#include #include #include #include #include #include #include using namespace std; struct Edge { int to; int weight; int id; }; int N; vector> adj; vector, int>> edges_output; vector path_res; bool found_path; bool is_square(int n) { if (n < 0) return false; int root = round(sqrt(n)); return root * root == n; } void dfs(int u, int target, int current_sum, vector& current_path, vector& vis) { if (found_path) return; if (u == target) { if (is_square(current_sum)) { found_path = true; path_res = current_path; } return; } for (const auto& edge : adj[u]) { if (!vis[edge.to]) { vis[edge.to] = true; current_path.push_back(edge.id); dfs(edge.to, target, current_sum + edge.weight, current_path, vis); current_path.pop_back(); vis[edge.to] = false; } } } bool check_all_pairs() { for (int i = 1; i <= N; ++i) { for (int j = i + 1; j <= N; ++j) { found_path = false; vector vis(N + 1, false); vector current_path; vis[i] = true; dfs(i, j, 0, current_path, vis); if (!found_path) return false; } } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); if (!(cin >> N)) return 0; vector even_weights; for (int i = 2; i <= 200; i += 2) { even_weights.push_back(i); } mt19937 rng(1337); while (true) { shuffle(even_weights.begin(), even_weights.end(), rng); adj.assign(N + 1, vector()); edges_output.clear(); int edge_count = 1; for (int i = 1; i < N; ++i) { int weight = 2 * i - 1; adj[i].push_back({i + 1, weight, edge_count}); adj[i + 1].push_back({i, weight, edge_count}); edges_output.push_back({{i, i + 1}, weight}); edge_count++; } for (int i = 1; i <= N - 2; ++i) { int weight = even_weights[i - 1]; adj[i].push_back({i + 2, weight, edge_count}); adj[i + 2].push_back({i, weight, edge_count}); edges_output.push_back({{i, i + 2}, weight}); edge_count++; } if (check_all_pairs()) { break; } } cout << edges_output.size() << "\n"; for (const auto& e : edges_output) { cout << e.first.first << " " << e.first.second << " " << e.second << "\n"; } for (int i = 1; i <= N; ++i) { for (int j = i + 1; j <= N; ++j) { found_path = false; vector vis(N + 1, false); vector current_path; vis[i] = true; dfs(i, j, 0, current_path, vis); cout << path_res.size() << "\n"; for (int k = 0; k < path_res.size(); ++k) { cout << path_res[k] << (k == path_res.size() - 1 ? "" : " "); } cout << "\n"; } } return 0; }