• 1006: [HNOI2008]神奇的国度


    图上的最小的染色方案;

    学习了陈丹绮的论文: MCS算法

    #include<cstdio>
    #define maxn 10005
    #define maxm 2000005
    using namespace std;
    
    int head[maxn],next[maxm],edge[maxm];
    int cnt;
    int d[maxn],f[maxn];
    
    void add(int a,int b)
    {
        edge[++cnt]=b;
        next[cnt]=head[a];
        head[a]=cnt;
    }
    
    int main()
    {
        int n,m,x,y;
        scanf("%d%d",&n,&m);
        while(m--)
        {
            scanf("%d%d",&x,&y);
            add(x,y);
            add(y,x);
        }
        d[0]=-1;
        int ans=0;
        for(int i=n; i>0; i--)
        {
            int k=0;
            for(int j=1;j<=n;j++)
                if(!f[j]&&d[j]>d[k])k=j;//chose the k with the max label;
            f[k]=i;
            for(int j=head[k];j;j=next[j])
                if(!f[edge[j]])
                    ++d[edge[j]];//add one in label for adject vertex of k;
        }
        for(int i=1;i<=n;i++)
            if(d[i]>ans)ans=d[i];
        printf("%d
    ",ans+1);
        return 0;
    }
    View Code
  • 相关阅读:
    Binary Tree Paths
    Implement Stack using Queues
    Path Sum II
    Path Sum
    Plus One
    Add Digits
    Missing Number
    H-Index II
    H-Index
    Ugly Number II
  • 原文地址:https://www.cnblogs.com/yours1103/p/3457956.html
Copyright © 2020-2023  润新知