Minimum coloring of chord graphs ... First use MCS to find the perfect elimination sequence and then the violent dyeing ...
-------------------------------------------------------------------------------------
#include <bits/stdc++.h>using namespace std;const int MAXN = 10009;inline int Read () {char C = getchar ();int ret = 0;For (;!isdigit (c); c = GetChar ());For (; IsDigit (c); c = GetChar ())ret = ret * + C-' 0 ';return ret;}struct Edge {int to;edge* Next;} e[2000009], *pt = E, *HEAD[MAXN];inline void Add (int u, int v) {pt->to = v; pt->next = head[u]; Head[u] = pt++;}inline void Addedge (int u, int v) {Add (U, v); Add (v, u);}int N, LABEL[MAXN], SEQ[MAXN], F[MAXN], COLOR[MAXN];bool DONE[MAXN];stack<int> S[MAXN];void init () {N = read ();int m = read ();While (m--) {int u = Read ()-1, v = Read ()-1;Addedge (U, v);}}void MCS () {for (int i = 0; i < N; i++) {Done[i] = false;Label[i] = 0;S[0].push (i);}int best = 0;for (int i = N; i--;) {for (;;) {While (! S[best].empty () && done[s[best].top ()]) s[best].pop ();if (! S[best].empty ()) break;else best--;}int x = S[best].top (); S[best].pop ();Done[seq[i] = x] = true;For (edge* e = head[x]; e; e = e->next) if (!done[e->to]) {if (++label[e->to] > Best) best = label[e->to];S[label[e->to]].push (e->to);}}} void Solve () {int ans = 0;memset (color, 0, sizeof color);memset (F,-1, sizeof f);for (int i = N; i--;) {int x = seq[i];For (edge* e = head[x]; e; e = e->next)F[color[e->to]] = x;for (int i = 1; I <= N; i++) if (f[i]! = x) {ans = max (ans, color[x] = i);Break ;}}printf ("%d\n", ans);}int main () {init ();MCS ();solve ();return 0;}
-------------------------------------------------------------------------------------
1006: [HNOI2008] Magical Country Time Limit: Sec Memory Limit: 162 MB
Submit: 2487 Solved: 1120
[Submit] [Status] [Discuss] Description
K Country is a country of keen triangles, even people's contacts only like the triangle principle. They think triangular relationship: AB Mutual understanding, BC Mutual Understanding, CA mutual understanding, is concise and efficient. In order to consolidate triangular relations, the K-State prohibits the existence of four-sided relations, five-sided relations and so on ... There is only n pairs of cognitive relationships between an: (A1A2) (A2A3) ... (AnA1), and there is no other understanding. For example, four-sided relationship refers to ABCD four people ab,bc,cd,da mutual understanding, and ac,bd do not know. When the national competition, in order to prevent the harm, the provision of any pair of mutual understanding of the person must not be in a team, the king knows, at least how many detachment.
Input
The first row of two integers n,m. 1<=n<=10000,1<=m<=1000000. Indicates that there are N individuals, M to the cognitive relationship. Next, enter a pair of friends on each line of M line
Output
Output an integer, at least how many teams can be divided
Sample Input4 5
1 2
1 4
2 4
2 3
3 4Sample Output3HINT
One scenario (1,3) (2) (4)
Source
Bzoj 1006: [HNOI2008] Magical Kingdom (MCS)