BZOJ 1006: [HNOI2008]神奇的国度 最大势算法

1006: [HNOI2008]神奇的国度

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


最大势算法 也不知道是啥 抄一遍板子就会了。。。

lkhll加点访问量吧。。


#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}
void print(int x)
{if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}

const int N=10100,M=1001000;

int ecnt,last[N];
struct EDGE{int to,nt;}e[M<<1];
inline void add(int u,int v)
{e[++ecnt]=(EDGE){v,last[u]};last[u]=ecnt;}

struct node{int val,pos;friend bool operator <(const node &x,const node &y){return x.val<y.val;}};

int num[N],col[N],d[N],cur[N];

bool vis[N];

priority_queue<node>q;

int main()
{
	int n=read(),m=read(),mx=0;
	register int i,j,u,v;
	for(i=1;i<=m;++i)u=read(),v=read(),add(u,v),add(v,u);
	for(i=1;i<=n;++i)q.push((node){0,i});
	for(i=n;i;i--)
	{
		while(vis[q.top().pos])q.pop();
		u=q.top().pos;q.pop();
		vis[u]=1;num[i]=u;
		for(j=last[u];j;j=e[j].nt)if(!vis[e[j].to])
		q.push((node){++d[e[j].to],e[j].to});
	}
	for(i=n;i;i--)
	{
		u=num[i];
		for(j=last[u];j;j=e[j].nt)if(col[e[j].to])cur[col[e[j].to]]=i;
		for(j=1;j<=mx;++j)if(cur[j]^i){col[u]=j;break;}
		if(!col[u])col[u]=++mx;
	}
	print(mx);puts("");
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值