#include <bits/stdc++.h>
using namespace std;
int n, m, k;
vector<pair<int, int>> pr;
int ST = 0;
int minM(int sp, set<int> &mt, int K, set<int> &b)
{
if (mt.size() >= k)
return 2137;
if (sp == m)
return mt.size();
if (K == pr[sp].first || K == pr[sp].second)
return minM(sp + 1, mt, K, b);
bool f = mt.count(pr[sp].first) || mt.count(pr[sp].second);
if (f)
return minM(sp + 1, mt, K, b);
int mi = 2137;
if (b.count(pr[sp].first) == 0)
{
b.insert(pr[sp].second);
mt.insert(pr[sp].first);
mi = minM(sp, mt, K, b);
mt.erase(pr[sp].first);
b.erase(pr[sp].second);
}
if (b.count(pr[sp].second) == 0)
{
b.insert(pr[sp].first);
mt.insert(pr[sp].second);
mi = min(mi, minM(sp, mt, K, b));
mt.erase(pr[sp].second);
b.erase(pr[sp].first);
}
// ST++;
// if (ST % 1000000 == 0)
// cout << ST << ' ' << flush;
return mi;
}
void solve()
{
set<pair<int, int>> se;
pr.clear();
cin >> n >> m >> k;
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
if (a > b)
swap(a, b);
// if (se.count({a, b}))
// continue;
se.insert({a, b});
pr.push_back({a, b});
}
vector<pair<int, int>> wn;
vector<vector<int>> al[n + 1], Ne[n + 1];
for (int i = 1; i <= n; i++)
{
vector<int> zm;
for (int j = 0; j < pr.size(); j++)
{
if (pr[j].first != i && pr[j].second != i)
zm.push_back(j);
}
al[i].push_back(zm);
}
bool f = 0;
set<int> p, q;
// m /= 10;
// 65535
// 511
// 301000000
for (int i = 1; i <= n; i++)
{
// ST = 0;
int wnn = minM(0, p, i, q);
// if (i == 1)
// cout << ST << '\n'
// << flush;
if (wnn < k)
wn.push_back({wnn + 1, i});
// cout << i << ' ' << wnn << '\n';
}
sort(wn.begin(), wn.end());
if (wn.size() == 0)
{
cout << "-1\n";
return;
}
vector<int> odp;
for (auto i : wn)
{
if (i.first == wn[0].first)
odp.push_back(i.second);
}
sort(odp.begin(), odp.end());
cout << wn[0].first << ' ' << odp.size() << '\n';
for (auto i : odp)
cout << i << ' ';
cout << '\n';
}
int main()
{
ios_base::sync_with_stdio(0);
int n;
cin >> n;
while (n--)
solve();
}
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | #include <bits/stdc++.h> using namespace std; int n, m, k; vector<pair<int, int>> pr; int ST = 0; int minM(int sp, set<int> &mt, int K, set<int> &b) { if (mt.size() >= k) return 2137; if (sp == m) return mt.size(); if (K == pr[sp].first || K == pr[sp].second) return minM(sp + 1, mt, K, b); bool f = mt.count(pr[sp].first) || mt.count(pr[sp].second); if (f) return minM(sp + 1, mt, K, b); int mi = 2137; if (b.count(pr[sp].first) == 0) { b.insert(pr[sp].second); mt.insert(pr[sp].first); mi = minM(sp, mt, K, b); mt.erase(pr[sp].first); b.erase(pr[sp].second); } if (b.count(pr[sp].second) == 0) { b.insert(pr[sp].first); mt.insert(pr[sp].second); mi = min(mi, minM(sp, mt, K, b)); mt.erase(pr[sp].second); b.erase(pr[sp].first); } // ST++; // if (ST % 1000000 == 0) // cout << ST << ' ' << flush; return mi; } void solve() { set<pair<int, int>> se; pr.clear(); cin >> n >> m >> k; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; if (a > b) swap(a, b); // if (se.count({a, b})) // continue; se.insert({a, b}); pr.push_back({a, b}); } vector<pair<int, int>> wn; vector<vector<int>> al[n + 1], Ne[n + 1]; for (int i = 1; i <= n; i++) { vector<int> zm; for (int j = 0; j < pr.size(); j++) { if (pr[j].first != i && pr[j].second != i) zm.push_back(j); } al[i].push_back(zm); } bool f = 0; set<int> p, q; // m /= 10; // 65535 // 511 // 301000000 for (int i = 1; i <= n; i++) { // ST = 0; int wnn = minM(0, p, i, q); // if (i == 1) // cout << ST << '\n' // << flush; if (wnn < k) wn.push_back({wnn + 1, i}); // cout << i << ' ' << wnn << '\n'; } sort(wn.begin(), wn.end()); if (wn.size() == 0) { cout << "-1\n"; return; } vector<int> odp; for (auto i : wn) { if (i.first == wn[0].first) odp.push_back(i.second); } sort(odp.begin(), odp.end()); cout << wn[0].first << ' ' << odp.size() << '\n'; for (auto i : odp) cout << i << ' '; cout << '\n'; } int main() { ios_base::sync_with_stdio(0); int n; cin >> n; while (n--) solve(); } |
English