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<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> #include<stack> #include<map> #include<set> #include<vector> #include<queue> #include<string> #include<cmath> using namespace std; #define ll long long #define rep(i,n) for(int i =0; i < n; ++i) #define CLR(x) memset(x,0,sizeof x) #define MEM(a,b) memset(a,b,sizeof a) #define pr(x) cout << #x << " = " << x << " "; #define prln(x) cout << #x << " = " << x << endl; const int maxn = 4e5+100; const int INF = 0x3f3f3f3f; int a[100], b[100], c[100]; bool vis[110][110]; struct Slove{ int head[22], nxt[210], to[210], edgenum; int check[22]; int match[22]; int left_num, right_num; int n; void init(int _n){ n =_n; left_num = right_num = n; memset(head, -1, sizeof head); edgenum = 0; } void addedge(int u, int v){ nxt[edgenum] = head[u]; to[edgenum] = v; head[u] = edgenum++; } bool dfs(int u){ for(int i = head[u]; ~i; i = nxt[i]){ int v = to[i]; if(!check[v]){ check[v] = true; if(match[v] == -1 || dfs(match[v])) { match[u] = v; match[v] = u; return true; } } } return false; } int hungry(){ int ans = 0; memset(match, -1, sizeof match); for(int i = 1; i <= left_num; ++i){ if(match[i] == -1){ memset(check, 0, sizeof check); if(dfs(i)) ++ans; } } return ans; } }solve; int main(){ #ifdef LOCAL freopen("/home/zeroxf/桌面/in.txt","r",stdin); #endif int n, m; int u, v; while(cin >> n >> m){ memset(vis, 0, sizeof vis); for(int i = 0; i < m; ++i){ scanf("%d%d", &u, &v); vis[u][v] = true; } if(n == 0) printf("0\n"); if(n < 1) continue; int d[] = {1,2,3,4,5,6,7,8,9,10}; int ans = 0; do{ solve.init(n); int temp = d[n]; d[n] = d[0]; for(int i = 1; i <= n; ++i) { for(int j = 1; j <= n; ++j){ int x = d[j-1]; if(!vis[i][x] && !vis[i][d[j]]){ solve.addedge(i, x+n); solve.addedge(x+n, i); } } } d[n] = temp; ans = max(ans, solve.hungry()); }while(next_permutation(d, d+n-1)); printf("%d\n", n-ans); } return 0; }
|