Question:
There are N knights, which provide the relationship of hatred between some of them. During the meeting, the knights will sit around a round table. A meeting can be held smoothly, meeting two conditions:
1: Any two servers that hate each other cannot be adjacent.
2: The number of participants is an odd number greater than 2.
If a server guard cannot participate in any meeting, he must be kicked out to give a hate relationship between the server guard and ask how many server guard should be kicked at least?
Ideas:
The question requires the least people to kick out, so you should be able to sit down as far as possible, and should not be adjacent to the hateful knight. The question is about the relationship of hatred between the knights. Therefore, we first establish a supplementary diagram. First, we establish the relationship of hatred based on the vertices of the server guard, and then cancel these edges, connecting the remaining edges can be a complementary image of the source image. The server guard must be able to sit in a round table, that is, the vertex in the figure can be in a circle,That is, in a dual-connected component, the number of people who want to meet the question is an odd number greater than 2.,This question is to find the maximum number of knights in the odd circle.
The maximum number of knights in the odd circle is required. We need to acknowledge the two theorems about the odd circle:
1: if there is an odd circle in the double connected component, all vertices in the double connected component are in a certain Odd Circle.
2: If a dual-connected component has an odd circle, the dual-connected component must not be a bipartite graph. They are necessary. You can use cross-staining to determine whether a bipartite graph is used. That is, if the subnode of a node is found to be stained and the subnode is the same as itself, it indicates that the subnode is not a bipartite graph, then there is an odd circle in the connected component.
Note that the number of vertices in the connected component is not related to whether the connected component is an odd circle.
We can use tarjan to find each dual-connected component. When the vertex is greater than 2, we can determine whether there is an odd ring for each pair of connected components obtained, you do not need to delete all vertices in the connected component (just mark them ).
Finally, the unlabeled vertex is certainly not a vertex in any odd circle.
# Include
# Include
# Include
# Include
Using namespace std; const int maxn = 1010; const int maxm = 1000100; int map [maxn] [maxn]; int n, m; int dfn [maxn], low [maxn], instack [maxn], dep; int scc, tmp [maxn], block [maxn]; int color [maxn]; // dye int expell [maxn] for a double-connected depth first search; // mark whether the vertex is in an odd circle int cnt; stack
St; vector
Edge [maxn]; // void init () {for (int I = 1; I <= n; I ++) edge [I]. clear (); while (! St. empty () st. pop (); memset (map, 0, sizeof (map); memset (dfn, 0, sizeof (dfn); memset (low, 0, sizeof (low )); memset (instack, 0, sizeof (instack); memset (block, 0, sizeof (block); memset (expell, 0, sizeof (expell); dep = 0; cnt = 0; scc = 0;} // judge the odd circle bool odd_cycle (int u, int col) {color [u] = col; for (int I = 0; I <(int) edge [u]. size (); I ++) {int v = edge [u] [I]; if (block [v] = scc) {if (color [v] & color [v] = color [u]) return tru E; if (! Color [v] & odd_cycle (v,-col) return true ;}return false;} void tarjan (int u, int fa) {dfn [u] = low [u] = ++ dep; instack [u] = 1; st. push (u); for (int I = 0; I <(int) edge [u]. size (); I ++) {int v = edge [u] [I]; if (v = fa) continue; if (! Dfn [v]) {tarjan (v, u); low [u] = min (low [u], low [v]); if (low [v]> = dfn [u]) {scc ++; int t; do {t = st. top (); st. pop (); instack [t] = 0; tmp [++ cnt] = t; block [t] = scc;} while (t! = V); // do not let the u out of the stack, because it may belong to multiple double-connected components tmp [++ cnt] = u; // u into the temporary array memset (color, 0, sizeof (color); if (cnt> = 3 & odd_cycle (u, 1 )) // if the number of vertices in the Two-link component is greater than 2 and it is an odd circle, {while (cnt! = 0) expell [tmp [cnt --] = 1; // all points in the odd circle are marked as 1} else cnt = 0; // do not forget to set cnt to zero} else if (instack [v]) low [u] = min (low [u], dfn [v]);} int main () {int u, v; while (~ Scanf (% d, & n, & m) {if (n = 0 & m = 0) break; init (); for (int I = 0; I <m; I ++) {scanf (% d, & u, & v ); map [u] [v] = map [v] [u] = 1;} // find the complement graph for (int I = 1; I <= n-1; I ++) {for (int j = I + 1; j <= n; j ++) {if (! Map [I] [j]) {edge [I]. push_back (j); edge [j]. push_back (I) ;}}for (int I = 1; I <= n; I ++) if (! Dfn [I]) tarjan (I,-1); int res = 0; for (int I = 1; I <= n; I ++) if (expell [I] = 0) res ++; printf (% d, res);} return 0 ;}