1 #include<stdio.h> 2 #include<string.h> 3 const int N = 1010; 4 const int M = 3000000; 5 struct Edge { 6 int u, v, next; 7 Edge() {} 8 Edge(int u, int v, int next) : u(u), v(v), next(next) {} 9 }E[M]; 10 int head[N], tot; 11 12 void addEdge(int u, int v) { 13 E[tot] = Edge(u, v, head[u]); 14 head[u] = tot++; 15 E[tot] = Edge(v, u, head[v]); 16 head[v] = tot++; 17 } 18 19 int pre[N], iscut[N], bccno[N], dfs_colock, bcc_cnt, bcc[N][N], bcc_size[N]; 20 Edge S[M]; 21 int ST; 22 23 int color[N]; 24 bool bipartite(int u, int b) { 25 for(int i = head[u]; i != -1; i = E[i].next) { 26 int v = E[i].v; if(bccno[v] != b) continue; 27 if(color[v] == color[u]) return false; 28 if(!color[v]) { 29 color[v] = 3 - color[u]; 30 if(!bipartite(v, b)) return false; 31 } 32 } 33 return true; 34 } 35 36 int min(int a, int b) { return a < b ? a : b; } 37 int dfs(int u, int fa) { 38 int lowu = pre[u] = ++dfs_colock; 39 int child = 0; 40 for(int i = head[u]; i != -1; i = E[i].next) { 41 int v = E[i].v; 42 Edge e = Edge(u, v, -1); 43 if(!pre[v]) { 44 S[++ST] = e; 45 child++; 46 int lowv = dfs(v, u); 47 lowu = min(lowu, lowv); 48 if(lowv >= pre[u]) { 49 iscut[u] = true; 50 bcc_cnt++; bcc_size[bcc_cnt] = 0; 51 while(1) { 52 Edge x = S[ST--]; 53 if(bccno[x.u] != bcc_cnt) { 54 bcc[bcc_cnt][bcc_size[bcc_cnt]++] = x.u; 55 bccno[x.u] = bcc_cnt; 56 } 57 if(bccno[x.v] != bcc_cnt) { 58 bcc[bcc_cnt][bcc_size[bcc_cnt]++] = x.v; 59 bccno[x.v] = bcc_cnt; 60 } 61 if(x.u == u && x.v == v) break; 62 } 63 } 64 } 65 else if(pre[v] < pre[u] && v != fa) { 66 S[++ST] = e; 67 lowu = min(lowu, pre[v]); 68 } 69 } 70 if(fa < 0 && child == 1) iscut[u] = 0; 71 return lowu; 72 } 73 74 void find_bcc(int n) { 75 memset(pre, 0, sizeof(pre)); 76 memset(iscut, 0, sizeof(iscut)); 77 memset(bccno, 0, sizeof(bccno)); 78 dfs_colock = bcc_cnt = 0; 79 for(int i = 0; i < n; ++i) 80 if(!pre[i]) dfs(i, -1); 81 } 82 int A[N][N]; 83 int main() { 84 int kase = 0, n, m; 85 while(scanf("%d%d", &n, &m) && n) { 86 memset(head, -1, sizeof(head)); 87 memset(A, 0, sizeof(A)); 88 for(int i = 0; i < m; ++i) { 89 int u, v; 90 scanf("%d%d", &u, &v); u--; v--; A[u][v] = A[v][u] = 1; 91 } 92 for(int i = 0; i < n; ++i) 93 for(int j = i + 1; j < n; ++j) 94 if(!A[i][j]) addEdge(i, j); 95 find_bcc(n); 96 int odd[N] ={0}; 97 for(int i = 1; i<= bcc_cnt; ++i) { 98 memset(color, 0, sizeof(color)); 99 for(int j = 0; j < bcc_size[i]; ++j) bccno[bcc[i][j]] = i; 100 int u = bcc[i][0]; 101 color[u] = 1; 102 if(!bipartite(u, i)) 103 for(int j = 0; j < bcc_size[i]; ++j) odd[bcc[i][j]] = 1; 104 } 105 int ans = n; 106 for(int i = 0; i < n; ++i) if(odd[i]) ans--; 107 printf("%d\n", ans); 108 } 109 return 0; 110 }