#include <iostream> #include <algorithm> void PrintTree(int ones) { std::cout << 2 - std::min(ones, 2) << '\n'; std::cout << 2 << '\n'; std::cout << "1 2\n"; } int main() { std::ios_base::sync_with_stdio(false); int n; std::cin >> n; int ones = 0; for (int i = 0; i < n; i++) { int deg; std::cin >> deg; if (deg == 1) { ++ones; } } PrintTree(ones); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <iostream> #include <algorithm> void PrintTree(int ones) { std::cout << 2 - std::min(ones, 2) << '\n'; std::cout << 2 << '\n'; std::cout << "1 2\n"; } int main() { std::ios_base::sync_with_stdio(false); int n; std::cin >> n; int ones = 0; for (int i = 0; i < n; i++) { int deg; std::cin >> deg; if (deg == 1) { ++ones; } } PrintTree(ones); return 0; } |