http://www.lydsy.com/JudgeOnline/problem.php?id=1006 (Topic link)
Test instructions
The minimum number of staining for the chord graph is obtained.
Solution
string diagram, see paper for details.
Here I write the Gar of the Nlogn, linear with the N list of links to maintain a bit and then hit the mark to delete on the line.
Details
WA took 2 rounds.
Code
bzoj1006#include<algorithm> #include <iostream> #include <cstdlib> #include <cstring># include<cstdio> #include <cmath> #include <queue> #define LL long long#define inf 1<<30#define Pi ACOs ( -1.0) #define FREE (a) freopen (a ".", "R", stdin), Freopen (a ". Out", "w", stdout); using namespace Std;const int maxn= 10010,maxm=1000010;int label[maxn],vis[maxn],head[maxn],c[maxn],a[maxn];int n,m,cnt;struct Edge {int to,next;} e[maxm<<1];struct Data {int id,w;friend bool operator < (const data A,const data b) {return a.w<b.w;}}; void link (int u,int v) {e[++cnt]= (edge) {v,head[u]};head[u]=cnt;e[++cnt]= (edge) {u,head[v]};head[v]=cnt;} void color (int x) {for (int i=head[x];i;i=e[i].next) vis[c[e[i].to]]=x;for (int i=1;i<=cnt;i++) if (vis[i]!=x) {c[x]=i ; break;} if (!c[x]) c[x]=++cnt;} int main () {scanf ("%d%d", &n,&m), for (int u,v,i=1;i<=m;i++) {scanf ("%d%d", &u,&v); link (u,v);} Priority_queue<data> Q;q.push (data) {n,0}); int tot=0;while (!q.emPty ()) {int x=q.top (). Id;q.pop (); if (Vis[x]) continue;vis[x]=1;a[++tot]=x;for (int i=head[x];i;i=e[i].next) if (!vis[e [i].to]) {Label[e[i].to]++;q.push ((data) {e[i].to,label[e[i].to]});}} memset (vis,0,sizeof (Vis)), cnt=0;for (int i=1;i<=n;i++) color (a[i]);p rintf ("%d", CNT); return 0;}
"bzoj1006" hnoi2008-The Magical kingdom