BZOJ 1006: [HNOI2008]神奇的国度 最大势算法
2017-09-20 20:41
323 查看
1006: [HNOI2008]神奇的国度
Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 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 51 2
1 4
2 4
2 3
3 4
Sample Output
3HINT
一种方案(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
;
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
,col
,d
,cur
;
bool vis
;
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;
}
相关文章推荐
- bzoj 1006: [HNOI2008]神奇的国度 -- 弦图(最大势算法)
- [BZOJ 1006][HNOI2008]神奇的国度(弦图染色、最大势算法)
- bzoj1006 [HNOI2008]神奇的国度(求弦图的色数,最大势算法)
- BZOJ 1006 [HNOI2008]神奇的国度==最大势算法
- [bzoj1006]: [HNOI2008]神奇的国度(最大势算法)
- BZOJ 1006: [HNOI2008]神奇的国度(最大势算法-弦图染色)
- bzoj 1006: [HNOI2008]神奇的国度 弦图最小染色 最大势算法
- [弦图 最小染色 完美消除序列 MCS算法] BZOJ 1006 [HNOI2008]神奇的国度
- bzoj1006: [HNOI2008]神奇的国度 [弦图染色CMS算法]
- BZOJ 1006 HNOI2008 神奇的国度 弦图最小染色 MCS算法
- bzoj1006 [HNOI2008]神奇的国度
- 【最小染色】【HNOI 2008】【bzoj 1006】神奇的国度
- BZOJ 1006 [HNOI2008]神奇的国度 弦图的最小染色
- BZOJ 1006: [HNOI2008]神奇的国度 弦圖
- BZOJ 1006 [HNOI2008]神奇的国度
- BZOJ 1006 [HNOI2008]神奇的国度
- BZOJ 1006 [HNOI2008] 神奇的国度(简单弦图的染色)
- bzoj 1006: [HNOI2008]神奇的国度
- BZOJ1006: [HNOI2008]神奇的国度
- BZOJ 1006 [HNOI2008]神奇的国度