#include <algorithm> #include <cstdio> #include <vector> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define VAR(v,w) __typeof(w) v=(w) #define FORE(it,c) for(VAR(it,(c).begin());it!=(c).end();++it) #define PB push_back #define SIZE(c) ((int)(c).size()) #define INT(x) int x; scanf("%d", &x) typedef vector<int> VI; typedef vector<VI> VVI; VVI g; int n, k; bool match[1000]; int res[1000]; int go(int i, int r) { if (r >= k) return k; if (i == n) return r; if (match[i]) return go(i + 1, r); match[i] = 1; int best = -1; FORE(it,g[i]) if (!match[*it]) { match[*it] = 1; best = max(best, go(i + 1, r + 1)); match[*it] = 0; } if (best == -1) best = go(i + 1, r); match[i] = 0; return best; } void oneCase() { INT(n1); n = n1; INT(m); INT(k1); k = k1; g.clear(); g.resize(n); REP(i,m) { INT(a); INT(b); --a; --b; g[a].PB(b); } REP(i,n) { match[i] = 1; res[i] = go(0, 0); match[i] = 0; } int mi = 1000000000; REP(i,n) mi = min(mi, res[i]); if (mi >= k) { printf("-1\n"); return; } VI v; REP(i,n) if (res[i] == mi) v.PB(i + 1); printf("%d %d\n", mi + 1, SIZE(v)); bool start = 1; FORE(it,v) { if (!start) printf(" "); start = 0; printf("%d", *it); } printf("\n"); } int main() { INT(t); REP(tt,t) oneCase(); }
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 | #include <algorithm> #include <cstdio> #include <vector> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define VAR(v,w) __typeof(w) v=(w) #define FORE(it,c) for(VAR(it,(c).begin());it!=(c).end();++it) #define PB push_back #define SIZE(c) ((int)(c).size()) #define INT(x) int x; scanf("%d", &x) typedef vector<int> VI; typedef vector<VI> VVI; VVI g; int n, k; bool match[1000]; int res[1000]; int go(int i, int r) { if (r >= k) return k; if (i == n) return r; if (match[i]) return go(i + 1, r); match[i] = 1; int best = -1; FORE(it,g[i]) if (!match[*it]) { match[*it] = 1; best = max(best, go(i + 1, r + 1)); match[*it] = 0; } if (best == -1) best = go(i + 1, r); match[i] = 0; return best; } void oneCase() { INT(n1); n = n1; INT(m); INT(k1); k = k1; g.clear(); g.resize(n); REP(i,m) { INT(a); INT(b); --a; --b; g[a].PB(b); } REP(i,n) { match[i] = 1; res[i] = go(0, 0); match[i] = 0; } int mi = 1000000000; REP(i,n) mi = min(mi, res[i]); if (mi >= k) { printf("-1\n"); return; } VI v; REP(i,n) if (res[i] == mi) v.PB(i + 1); printf("%d %d\n", mi + 1, SIZE(v)); bool start = 1; FORE(it,v) { if (!start) printf(" "); start = 0; printf("%d", *it); } printf("\n"); } int main() { INT(t); REP(tt,t) oneCase(); } |