二次联通门 : BZOJ 1006: [HNOI2008]神奇的国度
/* BZOJ 1006: [HNOI2008]神奇的国度 弦图 然而SB的我就是看不懂为什么要这样做QAQ 大体做法就是 从大到小扫描每个点,找出与这个点相连的度数最大的点,扔进队列里 然后将这个度数最大的点作为当前点,将于此点相连的点度数都加1 从后往前扫描队列里的元素,进行染色,每个点都染上最小的颜色就好了。 */ #include <cstdio> #include <iostream> const int BUF = 12312323; char Buf[BUF], *buf = Buf; #define rg register #define Max 10009 inline void read (int &n) { for (n = 0; !isdigit (*buf); ++ buf); for (; isdigit (*buf); n = n * 10 + *buf - '0', ++ buf); } inline void cmax (int &a, int b) { if (b > a) a = b; } struct E { E *n; int v; } *list[Max], poor[Max * 300], *Ta = poor; bool is[Max]; int d[Max], q[Max], k[Max], c[Max]; int main (int argc, char *argv[]) { fread (buf, 1, BUF, stdin); E *e; int x, y, Answer = 0; int N, M, p, n; read (N), read (M); rg int i, j; for (i = 1, d[0] = -1; i <= M; ++ i) { read (x), read (y); ++ Ta, Ta->v = y, Ta->n = list[x], list[x] = Ta; ++ Ta, Ta->v = x, Ta->n = list[y], list[y] = Ta; } for (i = N; i >= 1; -- i) { for (j = 1, n = 0; j <= N; ++ j) if (!is[j] && d[j] > d[n]) n = j; for (is[n] = true, q[i] = n, e = list[n]; e; ++ d[e->v], e = e->n); } for (i = N; i >= 1; -- i) { for (e = list[q[i]]; e; k[c[e->v]] = i, e = e->n); for (j = 1; k[j] == i; ++ j); c[q[i]] = j; cmax (Answer, j); } printf ("%d", Answer); return 0; }