首页 技术 正文
技术 2022年11月15日
0 收藏 844 点赞 2,747 浏览 1598 个字

1006: [HNOI2008]神奇的国度

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

Description

  K国是一个热衷三角形的国度,连人的交往也只喜欢三角原则.他们认为三角关系:即AB相互认识,BC相互认识,CA
相互认识,是简洁高效的.为了巩固三角关系,K国禁止四边关系,五边关系等等的存在.所谓N边关系,是指N个人 A1A2
…An之间仅存在N对认识关系:(A1A2)(A2A3)…(AnA1),而没有其它认识关系.比如四边关系指ABCD四个人 AB,BC,C
D,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)

【题解】

由于题中的限制条件,建出来的图一定是一个弦图,要求的答案就是弦图的最小染色方案。

首先用MCS算法求出弦图的完美消除序列,然后从后往前染上可以染的最小颜色,记录一下答案就行了。

那么这么做为什么是对的呢?

证明:我们假设使用了T种颜色,则T>=色数,T=团数<=色数,所以T=色数。

时间复杂度:O(m+n)

参考:陈丹琦——《弦图与区间图》

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<algorithm>
using namespace std;
struct node{int y,next;}e[*];
int n,m,len,ans,Link[],label[],vis[],q[],check[],col[];
inline int read()
{
int x=,f=; char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-; ch=getchar();}
while(isdigit(ch)) {x=x*+ch-''; ch=getchar();}
return x*f;
}
void insert(int xx,int yy)
{
e[++len].next=Link[xx];
Link[xx]=len;
e[len].y=yy;
}
void MCS()//最大势算法求完美消除序列
{
for(int i=n;i;i--)
{
int now=;
for(int j=;j<=n;j++)
if(label[j]>=label[now]&&!vis[j]) now=j;
vis[now]=; q[i]=now;
for(int j=Link[now];j;j=e[j].next)
label[e[j].y]++;
}
}
void color()//染色
{
for(int i=n;i;i--)
{
int now=q[i],j;
for(int j=Link[now];j;j=e[j].next) check[col[e[j].y]]=i;
for(j=;;j++) if(check[j]!=i) break;
col[now]=j;
if(j>ans) ans=j;
}
}
int main()
{
n=read(); m=read();
for(int i=;i<=m;i++)
{
int x=read(),y=read();
insert(x,y); insert(y,x);
}
MCS();
color();
printf("%d\n",ans);
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902