Click to open link
Non-point graph points Double unicom, two-part chart determination
<span style= "FONT-SIZE:18PX;" > #include <cstdio> #include <stack> #include <vector> #include <algorithm> #include < cstring>using namespace Std;struct edge{int u, v;}; const int MAXN = 1005;int PRE[MAXN], ISCUT[MAXN], Bccno[maxn],dfs_clock, bcc_cnt;vector<int> G[MAXN], BCC[MAXN]; stack<edge> s;int dfs (int u, int fa) {int Lowu = pre[u] = ++dfs_clock; int child = 0; for (int i=0; i<g[u].size (); ++i) {int v = g[u][i]; Edge e = (edge) {u, v}; if (!pre[v]) {S.push (e); child++; int LOWV = DFS (v, u); Lowu = min (Lowu, LOWV); if (Lowv>=pre[u]) {Iscut[u] = true; bcc_cnt++; Bcc[bcc_cnt].clear (); for (;;) {Edge x = S.top (); S.pop (); if (bccno[x.u]!=bcc_cnt) {bcc[bcc_cnt].push_back (X.U); bccno[x.u] = bcc_cnt; } if (BCCNO[X.V]! = BCC_CNT) {bcc[bcc_cnt].push_back (X.V); bccno[x.v] = bcc_cnt; } if (X.u==u && x.v==v) break; }}} and else if (Pre[v]<pre[u] &&v!=fa) {s.push (e); Lowu = min (Lowu, pre[v]); }} if (FA < 0 && child = = 1) iscut[u] = 0; return LOWU;} void find_bcc (int n) {memset (pre, 0, sizeof pre); memset (iscut, 0, sizeof iscut); memset (bccno, 0, sizeof bccno); Dfs_clock = bcc_cnt = 0; for (int i=0; i<n; ++i) if (!pre[i]) DFS (i,-1);} int ODD[MAXN], color[maxn];bool bipartite (int u, int b) {for (int i=0; i<g[u].size (); ++i) {int v = g[u][i]; I F (bccno[v]!=b) continue; if (Color[v]==color[u]) return false; if (!color[v]) {Color[v] = 3-color[u]; if (!bipartite (V, b)) return false; }} return true; int A[maxn][maxn];int Main () {#ifndef Online_judge freopen ("In.cpp", "R", stdin); Freopen ("Out.cpp", "w", stdout), #endif//online_judge int kase = 0, n, m; while (scanf ("%d%d", &n, &m) ==2 &&n) {for (int i=0; i<n; ++i) g[i].clear (); memset (A, 0, sizeof a); for (int i=0; i<m; ++i) {int u, v; scanf ("%d%d", &u, &v); u--; v--; A[U][V] = A[v][u] = 1; } for (int u=0; u<n; ++u)//Avoid heavy edge for (int v=u+1; v<n; ++v) if (! A[u][v]) {g[u].push_back (v); G[v].push_back (U); } FIND_BCC (n); memset (odd, 0, sizeof odd); for (int i=1; i<=bcc_cnt; ++i) {memset (color, 0, sizeof color); for (int j=0; j<bcc[i].size (); ++j) Bccno[bcc[i][j]] = i; int u = bcc[i][0]; Color[u] = 1; if (!bipartite (U, i)) for (int j=0; j<bcc[i].size (); ++j) Odd[bcc[i][j]] = 1; } int ans = n; Forint i=0; i<n; ++i) if (odd[i]) ans--; printf ("%d\n", ans); } return 0;} </span>
poj2942 Knights of the Round Table, non-point map double Unicom, two-part chart determination