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

    1006: [HNOI2008]神奇的国度

    Time Limit: 20 Sec  Memory Limit: 162 MB
    Submit: 2346  Solved: 1059
    [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)

    Source

    题解:天哪,我发现BZOJ就是一道题一个知识点。。。这个考的是弦图染色。

    cdq神犇的论文 已经说的很清楚了,mcs还真是hentai啊。。。

    我才懒得写一个堆,反正能过就行

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<queue>
     6 #include<cstring>
     7 #define PAU putchar(' ')
     8 #define ENT putchar('
    ')
     9 using namespace std;
    10 const int maxn=10000+10,maxm=2000000+10,inf=-1u>>1;
    11 struct ted{int x,y;ted*nxt;}adj[maxm],*ms=adj,*fch[maxn];
    12 void add(int u,int v){
    13     *ms=(ted){u,v,fch[u]};fch[u]=ms++;
    14     *ms=(ted){v,u,fch[v]};fch[v]=ms++;
    15     return;
    16 }
    17 int n,m,ans,col[maxn],bcol[maxn],lab[maxn];bool vis[maxn];
    18 inline int read(){
    19     int x=0,sig=1;char ch=getchar();
    20     while(!isdigit(ch)){if(ch=='-') sig=-1;ch=getchar();}
    21     while(isdigit(ch)) x=10*x+ch-'0',ch=getchar();
    22     return x*=sig;
    23 }
    24 inline void write(int x){
    25     if(x==0){putchar('0');return;}if(x<0) putchar('-'),x=-x;
    26     int len=0,buf[15];while(x) buf[len++]=x%10,x/=10;
    27     for(int i=len-1;i>=0;i--) putchar(buf[i]+'0');return;
    28 }
    29 void init(){
    30     n=read();m=read();
    31     for(int i=1;i<=m;i++)add(read(),read());
    32     return;
    33 }
    34 void work(){
    35     for(int i=1;i<=n;i++){
    36         int mx=-1,k=0;
    37         for(int j=1;j<=n;j++)if(!vis[j]&&mx<lab[j])mx=lab[j],k=j;
    38         vis[k]=1;
    39         for(ted*e=fch[k];e;e=e->nxt){
    40             int v=e->y;if(!vis[v])lab[v]++;else bcol[col[v]]=i;
    41         }for(int j=1;j<=n;j++)if(bcol[j]^i){col[k]=j;ans=max(ans,j);break;}
    42     }
    43     return;
    44 }
    45 void print(){
    46     write(ans);
    47     return;
    48 }
    49 int main(){
    50     init();work();print();return 0;
    51 }
  • 相关阅读:
    力扣(LeetCode)922. 按奇偶排序数组 II
    力扣(LeetCode)1002. 查找常用字符
    力扣(LeetCode)15. 三数之和
    Java == 和 equals 区别
    力扣(LeetCode)125. 验证回文串
    力扣(LeetCode) 905. 按奇偶排序数组
    力扣(LeetCode)832. 翻转图像
    力扣(LeetCode) 771. 宝石与石头
    Sticks
    荷马史诗
  • 原文地址:https://www.cnblogs.com/chxer/p/4640693.html
Copyright © 2011-2022 走看看