[Bzoj 1006] [HNOI2008] The magical kingdom "minimum coloring of the chord graph"

Source: Internet
Author: User

Title Link: BZOJ-1006

Problem analysis

This problem is a bare model of the minimum number of staining figures for a chord graph.

The minimum coloring method of a string graph is to find out the perfect elimination sequence (MCS algorithm) of the chord graph, and then, in accordance with the perfect elimination sequence, backward forward from backward to the smallest color that each Dianran can dye.

The number of colors found is the smallest stain, but also the largest group.

Code
#include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> #include <cstring  > #include <algorithm> #include <queue>using namespace std;const int MAXN = 10000 + 5, MAXM = 1000000 + 5;int N, M, Ans;int V[MAXN], A[MAXN], COL[MAXN], used[maxn];bool visit[maxn];struct edge{int V; Edge *next;} E[MAXM * 2], *p = E, *point[maxn];inline void Addedge (int x, int y) {++p; P-v = y; P-Next = point[x]; POINT[X] = P;} struct Es{int p, q;es () {}es (int a, int b) {p = A; q = b;}}; struct Cmp{bool operator () (ES E1, es E2) {return e1.q < e2.q;}}; Priority_queue<es, Vector<es>, cmp> Q;//mcs the perfect elimination sequence void MCS () {for (int i = 1; I <= n; ++i) {v[i] = 0; Visit[i] = false;} while (! Q.empty ()) Q.pop (); Q.push (ES (1, 0)); int x, y;for (int i = n; i >= 1; i.) {while (true) {x = Q.top (). P; Q.pop (); if (! VISIT[X]) break; A[i] = x; VISIT[X] = true;for (Edge *j = point[x]; j; j = J-Next) {y = J-v;if (Visit[y]) continue;++v[y]; Q.push (ES (y, v[y]));}}} void Min_paint () {Ans = 1;int x;memset (col, 0, sizeof (COL)), memset (used, 0, sizeof (used)), for (int i = n; i >= 1; i.)  {for (Edge *j = Point[a[i]]; j; j = J-Next) Used[col[j-v]] = I;x = 1;while (used[x] = = i) {++x;if (x > Ans) Ans = x;} Col[a[i]] = x;}} int main () {scanf ("%d%d", &n, &m); int A, b;for (int i = 1; I <= m; ++i) {scanf ("%d%d", &a, &b); Addedge (A, b); Addedge (b, a);} MCS (); Min_paint ();p rintf ("%d\n", Ans); return 0;}

  

[Bzoj 1006] [HNOI2008] The magical kingdom "minimum coloring of the chord graph"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.