zoukankan      html  css  js  c++  java
  • [HNOI2008]神奇的国度

    1006: [HNOI2008]神奇的国度

    Time Limit: 20 Sec  Memory Limit: 162 MB
    [Submit][Status][Discuss]

    Description

      K国是一个热衷三角形的国度,连人的交往也只喜欢三角原则.他们认为三角关系:即AB相互认识,BC相互认识,CA相互认识,是简洁高效的.为了巩固三角关系,K国禁止四边关系,五边关系等等的存在.所谓N边关系,是指N个人 A1A2...An之间仅存在N对认识关系:(A1A2)(A2A3)...(AnA1),而没有其它认识关系.比如四边关系指ABCD四个人 AB,BC,CD,DA相互认识,而AC,BD不认识.全民比赛时,为了防止做弊,规定任意一对相互认识的人不得在一队,国王相知道,最少可以分多少支队。

    Input

      第一行两个整数N,M。1<=N<=10000,1<=M<=1000000.表示有N个人,M对认识关系. 接下来M行每行输入一对朋友

    Output

      输出一个整数,最少可以分多少队

    Sample Input

    4 5
    1 2
    1 4
    2 4
    2 3
    3 4

    Sample Output

    3

    HINT

      一种方案(1,3)(2)(4)

    弦图的点染色问题

    构造出完美消除序列后

    从后往前染当前能染的最小颜色

    #include<cstdio>
    #include<iostream>
    #define N 10001
    #define M 1000001
    using namespace std;
    bool vis[N];
    int st[N],top;
    int color[N],mark[N],sa[N],d[N];
    int n,m;
    int tot,front[N<<1],to[M*3],nxt[M*3];
    void read(int &x)
    {
        x=0; char c=getchar();
        while(!isdigit(c)) c=getchar();
        while(isdigit(c)) { x=x*10+c-'0'; c=getchar(); }
    }
    void add(int u,int v)
    {
        to[++tot]=v; nxt[tot]=front[u]; front[u]=tot;
    }
    #define f(x) x+n+1
    void mcs()
    {
        for(int i=1;i<=n;i++) add(f(0),i);
        int pos,mx=0;
        for(int i=n;i;--i)
        {
            pos=0;
            for(int j=front[f(mx)] ; j && !pos ; j=nxt[j])
                if(!vis[to[j]]) 
                {
                    pos=to[j];
                    vis[pos]=true;
                    sa[i]=pos;
                }
                else front[f(mx)]=nxt[j];
            if(!pos) mx--,i++;
            else
            {
                for(int j=front[pos];j;j=nxt[j])
                    if(!vis[to[j]])
                    {
                        d[to[j]]++;
                        add(f(d[to[j]]),to[j]);
                        mx=max(mx,d[to[j]]);
                    }
            }
        }
    }
    int main()
    {
        read(n); read(m);
        int u,v;
        for(int i=1;i<=m;++i) 
        {
            read(u); read(v);
            add(u,v);
            add(v,u);
        }
        mcs();
        int ans=0;
        for(int i=n;i;--i)
        {
            for(int j=front[sa[i]];j;j=nxt[j])
                mark[color[to[j]]]=i;
            int j;
            for(j=1;j<=n&&mark[j]==i;j++);
            color[sa[i]]=j;
            ans=max(ans,j);     
        }
        printf("%d",ans);    
    }
  • 相关阅读:
    51nod乘积之和
    Dell服务器安装OpenManage(OMSA)
    Nginx反向代理PHP
    搭建haproxy
    108. Convert Sorted Array to Binary Search Tree
    60. Permutation Sequence
    142. Linked List Cycle II
    129. Sum Root to Leaf Numbers
    118. Pascal's Triangle
    26. Remove Duplicates from Sorted Array
  • 原文地址:https://www.cnblogs.com/TheRoadToTheGold/p/7464788.html
Copyright © 2011-2022 走看看