SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <iostream> | |
| 2 | #include <sstream> | |
| 3 | #include <fstream> | |
| 4 | #include <iomanip> | |
| 5 | #include <string> | |
| 6 | #include <cstdlib> | |
| 7 | #include <cstdio> | |
| 8 | #include <cassert> | |
| 9 | #include <cstring> | |
| 10 | #include <cmath> | |
| 11 | #include <ctime> | |
| 12 | #include <climits> | |
| 13 | #include <vector> | |
| 14 | #include <queue> | |
| 15 | #include <stack> | |
| 16 | #include <set> | |
| 17 | #include <bitset> | |
| 18 | #include <map> | |
| 19 | #include <utility> | |
| 20 | #include <algorithm> | |
| 21 | #include <numeric> | |
| 22 | #include <functional> | |
| 23 | ||
| 24 | #define forn(i, n) for (int i = 0; i < int(n); i++) | |
| 25 | #define forl(i, n) for (int i = 1; i <= int(n); i++) | |
| 26 | #define ford(i, n) for (int i = int(n) - 1; i >= 0; i--) | |
| 27 | #define fore(i, l, r) for(int i = int(l); i <= int(r); i++) | |
| 28 | #define all(a) (a).begin(), (a).end() | |
| 29 | #define sz(a) int((a).size()) | |
| 30 | #define pb(a) push_back(a) | |
| 31 | #define mp(x, y) make_pair((x), (y)) | |
| 32 | #define ft first | |
| 33 | #define sc second | |
| 34 | #define x first | |
| 35 | #define y second | |
| 36 | ||
| 37 | using namespace std; | |
| 38 | ||
| 39 | template<typename X> inline X abs(const X& a) { return a < 0 ? -a : a; }
| |
| 40 | template<typename X> inline X sqr(const X& a) { return a * a; }
| |
| 41 | ||
| 42 | typedef long long li; | |
| 43 | typedef long double ld; | |
| 44 | typedef pair<int, int> pt; | |
| 45 | ||
| 46 | const int INF = int(1e9); | |
| 47 | const li INF64 = li(1e18); | |
| 48 | const ld EPS = 1e-9; | |
| 49 | ||
| 50 | const int N = 3000 + 3; | |
| 51 | ||
| 52 | int n, m, k; | |
| 53 | vector<int> g[N]; | |
| 54 | ||
| 55 | inline bool read() | |
| 56 | {
| |
| 57 | if (scanf("%d%d%d", &n, &m, &k) != 3) return false;
| |
| 58 | ||
| 59 | forn(i, m) | |
| 60 | {
| |
| 61 | int x, y; | |
| 62 | assert(scanf("%d%d", &x, &y) == 2);
| |
| 63 | x--, y--; | |
| 64 | g[x].pb(y), g[y].pb(x); | |
| 65 | } | |
| 66 | ||
| 67 | return true; | |
| 68 | } | |
| 69 | ||
| 70 | int ansVal; | |
| 71 | int used[N]; | |
| 72 | int perm[N]; | |
| 73 | ||
| 74 | int CNT = 200 * 1000 * 1000; | |
| 75 | ||
| 76 | void solve(int idx, int curVal) | |
| 77 | {
| |
| 78 | if (--CNT < 0) return; | |
| 79 | if (curVal > k) return; | |
| 80 | if (curVal >= ansVal) return; | |
| 81 | ||
| 82 | if (idx == n) return void(ansVal = curVal); | |
| 83 | ||
| 84 | int v = perm[idx]; | |
| 85 | ||
| 86 | if (used[v]) return solve(idx + 1, curVal); | |
| 87 | ||
| 88 | if (sz(g[v]) <= k) | |
| 89 | {
| |
| 90 | int nextVal = curVal; | |
| 91 | forn(j, sz(g[v])) | |
| 92 | {
| |
| 93 | nextVal += !used[g[v][j]]; | |
| 94 | used[g[v][j]]++; | |
| 95 | } | |
| 96 | ||
| 97 | solve(idx + 1, nextVal); | |
| 98 | ||
| 99 | forn(j, sz(g[v])) | |
| 100 | used[g[v][j]]--; | |
| 101 | } | |
| 102 | ||
| 103 | used[v]++; | |
| 104 | solve(idx + 1, curVal + 1); | |
| 105 | used[v]--; | |
| 106 | } | |
| 107 | ||
| 108 | inline bool cmp(int i, int j) { return sz(g[i]) > sz(g[j]); }
| |
| 109 | ||
| 110 | inline void solve() | |
| 111 | {
| |
| 112 | forn(i, n) perm[i] = i; | |
| 113 | sort(perm, perm + n, cmp); | |
| 114 | //reverse(perm, perm + n); | |
| 115 | //random_shuffle(perm, perm + n); | |
| 116 | ||
| 117 | ansVal = k + 1; | |
| 118 | solve(0, 0); | |
| 119 | if (ansVal == k + 1) puts("Impossible");
| |
| 120 | else cout << ansVal << endl; | |
| 121 | } | |
| 122 | ||
| 123 | int main() | |
| 124 | {
| |
| 125 | #ifdef SU2_PROJ | |
| 126 | assert(freopen("input.txt", "rt", stdin));
| |
| 127 | //assert(freopen("output.txt", "wt", stdout));
| |
| 128 | #endif | |
| 129 | ||
| 130 | assert(read()); | |
| 131 | solve(); | |
| 132 | ||
| 133 | return 0; | |
| 134 | } |