bzoj 1006: [HNOI2008]神奇的国度
2024-09-18 02:03:49
这是个标准的弦图,但如果不知道弦图就惨了=_=
趁着这个机会了解了一下弦图,主要就是完美消除序列,求出了这个就可以根据序列进行贪心染色。
貌似这个序列很神,但是具体应用不了解……
这道题为什么可以这么做不理解……
我真是太弱了……
上代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <queue>
#define N 100100
#define M 2000100
using namespace std;
struct sss
{
int num;
int du;
};
int n, m;
int p[N] = {}, next[M], v[M], bnum = ;
int du[N] = {}, vis[N] = {}, qu[N];
priority_queue<sss> q;
int hcolor[N] = {}, color[N] = {}, colornum = , huse[N] = {}; bool operator < (sss x, sss y)
{
return x.du < y.du;
} void addbian(int x, int y)
{
bnum++; next[bnum] = p[x]; p[x] = bnum; v[bnum] = y;
bnum++; next[bnum] = p[y]; p[y] = bnum; v[bnum] = x;
} void make_queue()
{
for (int i = ; i <= n; ++i)
{
sss x; x.num = i; x.du = ;
q.push(x);
}
int dc = ;
while (dc < n)
{
sss y = q.top(); q.pop();
while (vis[y.num])
{
y = q.top();
q.pop();
}
vis[y.num] = ;
qu[++dc] = y.num;
int k = p[y.num]; sss ne;
while (k)
{
if (!vis[v[k]])
{
du[v[k]]++; ne.du = du[v[k]];
ne.num = v[k]; q.push(ne);
}
k = next[k];
}
}
} void color_dian()
{
for (int i = ; i <= n; ++i)
{
int x = qu[i];
int k = p[x];
int all = ;
while (k)
{
if (color[v[k]] != ) all = ;
huse[color[v[k]]] = x;
k = next[k];
}
int pd = ;
for (int i = ; i <= colornum; ++i)
if (huse[i] != x)
{
pd = ;
color[x] = i;
break;
}
if (!pd) color[x] = ++colornum;
}
printf("%d\n", colornum);
} int main()
{
scanf("%d%d", &n, &m);
for (int i = ; i <= m; ++i)
{
int x, y; scanf("%d%d", &x, &y);
addbian(x, y);
}
make_queue();
color_dian();
return ;
}
最新文章
- mysql count(*)和count(列)速率
- 自用debug单元
- 100个iOS开发/设计面试题汇总
- sql server 判断是否存在数据库,表,列,视图
- javascript笔记——label包含的自定义按钮选中
- SQLServer 之 2008还原的时候无法获得对数据库的独占访问权解决
- [改善Java代码]子列表只是原列表的一个视图
- 解决weblogic与系统时间相差8小时的问题
- 在虚拟机上配置linux lab的相关经验
- 通过反射实现Json数据部分更新JavaBean的属性
- 3.3.2 PCI设备对不可Cache的存储器空间进行DMA读写
- Java:函数
- 使用newtonsoft序列化
- 如何用git上传代码到github详细步骤
- python的进程/线程/协程
- 读《移山之道——VSTS软件开发指南》
- 接口app 接口中上传 图片
- linux 关闭笔记本自带键盘
- pre 标签的使用注意事项
- PHP(六)PHP和HTML混合的一种形式