BZOJ1006: [HNOI2008]神奇的国度
2017-12-28 21:12
423 查看
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)
题目传送门
第一版就然真的是一个算法一个题吐槽...不过貌似效果不错??
新姿势:最大势算法,详情请见CDQ大佬的论文
看完论文你在看这道题,一下就可以简化题意:
求最少的颜色使相邻的两个点颜色不同
那么就最大势啊
实在不懂可以看我代码
自认为可见度还是挺高的
代码如下:
by_lmy
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)
题目传送门
第一版就然真的是一个算法一个题吐槽...不过貌似效果不错??
新姿势:最大势算法,详情请见CDQ大佬的论文
看完论文你在看这道题,一下就可以简化题意:
求最少的颜色使相邻的两个点颜色不同
那么就最大势啊
实在不懂可以看我代码
自认为可见度还是挺高的
代码如下:
#include<cmath> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> using namespace std; struct node{ int x,y,next,other; }a[2100000];int len,last[2100000]; void ins(int x,int y) { len++; a[len].x=x;a[len].y=y; a[len].next=last[x];last[x]=len; } int ans,n,m; bool v[210000]; int list[210000],d[210000]; int hash[210000],f[210000]; int main() { ans=0; scanf("%d%d",&n,&m); len=0;memset(last,0,sizeof(last)); for(int i=1;i<=m;i++) { int x,y; scanf("%d%d",&x,&y); ins(x,y),ins(y,x); } for(int i=n;i>=1;i--) { int x=0; for(int j=1;j<=n;j++) if(v[j]==false&&d[j]>=d[x])x=j; v[x]=true;list[i]=x; for(int k=last[x];k;k=a[k].next){int y=a[k].y;d[y]++;} } for(int i=n;i>=1;i--) { int x=list[i]; for(int k=last[x];k;k=a[k].next)hash[f[a[k].y]]=i; int j; for(j=1;j;j++) c654 if(hash[j]!=i)break; f[x]=j; if(j>ans)ans=j; } printf("%d\n",ans); return 0; }
by_lmy
相关文章推荐
- BZOJ 1006: [HNOI2008]神奇的国度(弦图染色)
- BZOJ 1006: [HNOI2008]神奇的国度(最大势算法-弦图染色)
- 【最小染色】【HNOI 2008】【bzoj 1006】神奇的国度
- BZOJ 1006 【HNOI2008】 神奇的国度
- [bzoj1006]: [HNOI2008]神奇的国度(最大势算法)
- BZOJ 1006: [HNOI2008]神奇的国度 &&弦图学习笔记
- BZOJ 1006 [HNOI2008]神奇的国度==最大势算法
- [bzoj1006][HNOI2008]神奇的国度 弦图
- bzoj1006 [HNOI2008]神奇的国度
- 【MCS】bzoj1006: [HNOI2008]神奇的国度
- BZOJ 1006 [HNOI2008]神奇的国度
- bzoj1006: [HNOI2008]神奇的国度
- [BZOJ1006][HNOI2008]神奇的国度(弦图最小染色)
- [BZOJ1006][[HNOI2008]神奇的国度][MCS,完美消除序列]
- [BZOJ]1006 [HNOI2008]神奇的国度
- BZOJ 1006 HNOI2008 神奇的国度 弦图最小染色 MCS算法
- ●BZOJ 1006 [HNOI2008]神奇的国度(弦图最小染色数)○ZOJ 1015 Fishing Net
- BZOJ 1006: [HNOI2008]神奇的国度
- BZOJ 1006: [HNOI2008]神奇的国度( MCS )
- BZOJ1006 HNOI2008 神奇的国度