#include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> degrees (n); for (int&d:degrees)cin>>d; vector<int>ones; vector<int>not_ones; for (int i=0;i<degrees.size();i++){ if (degrees[i]==1)ones.push_back(i); else not_ones.push_back(i); } int k = 0; while (ones.size() < 2) { k++; ones.push_back(not_ones.back()); not_ones.pop_back(); } cout << k << endl; cout << 2 << endl; cout << 1 << " " << 2 << endl; }
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 | #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> degrees (n); for (int&d:degrees)cin>>d; vector<int>ones; vector<int>not_ones; for (int i=0;i<degrees.size();i++){ if (degrees[i]==1)ones.push_back(i); else not_ones.push_back(i); } int k = 0; while (ones.size() < 2) { k++; ones.push_back(not_ones.back()); not_ones.pop_back(); } cout << k << endl; cout << 2 << endl; cout << 1 << " " << 2 << endl; } |