#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int q; cin >> q; int n, m, k; int* med; int a, b; int min; vector<int> mins; while (q--) { mins.clear(); cin >> n >> m >> k; min = m + 1; med = new int[n]; for (int i = 0; i < n; i++) { med[i] = m; } for (int i = 0; i < m; i++) { cin >> a >> b; med[a - 1]--; med[b - 1]--; if (med[a - 1] < min) { min = med[a - 1]; mins.clear(); } if (med[b - 1] < min) { min = med[b - 1]; mins.clear(); } if (med[a - 1] == min) { mins.push_back(a); } if (med[b - 1] == min) { mins.push_back(b); } } if (min + 1 > k) cout << "-1\n"; else { sort(mins.begin(), mins.end()); cout << min + 1 <<" "<< mins.size() << endl; for (int i = 0; i < mins.size(); i++) { cout << mins[i] << " "; } if (k > 0) cout << endl; } } 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int q; cin >> q; int n, m, k; int* med; int a, b; int min; vector<int> mins; while (q--) { mins.clear(); cin >> n >> m >> k; min = m + 1; med = new int[n]; for (int i = 0; i < n; i++) { med[i] = m; } for (int i = 0; i < m; i++) { cin >> a >> b; med[a - 1]--; med[b - 1]--; if (med[a - 1] < min) { min = med[a - 1]; mins.clear(); } if (med[b - 1] < min) { min = med[b - 1]; mins.clear(); } if (med[a - 1] == min) { mins.push_back(a); } if (med[b - 1] == min) { mins.push_back(b); } } if (min + 1 > k) cout << "-1\n"; else { sort(mins.begin(), mins.end()); cout << min + 1 <<" "<< mins.size() << endl; for (int i = 0; i < mins.size(); i++) { cout << mins[i] << " "; } if (k > 0) cout << endl; } } return 0; } |