这是个标准的弦图,但如果不知道弦图就惨了=_=

趁着这个机会了解了一下弦图,主要就是完美消除序列,求出了这个就可以根据序列进行贪心染色。

貌似这个序列很神,但是具体应用不了解……

这道题为什么可以这么做不理解……

我真是太弱了……

上代码:

#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 ;
}

最新文章

  1. mysql count(*)和count(列)速率
  2. 自用debug单元
  3. 100个iOS开发/设计面试题汇总
  4. sql server 判断是否存在数据库,表,列,视图
  5. javascript笔记——label包含的自定义按钮选中
  6. SQLServer 之 2008还原的时候无法获得对数据库的独占访问权解决
  7. [改善Java代码]子列表只是原列表的一个视图
  8. 解决weblogic与系统时间相差8小时的问题
  9. 在虚拟机上配置linux lab的相关经验
  10. 通过反射实现Json数据部分更新JavaBean的属性
  11. 3.3.2 PCI设备对不可Cache的存储器空间进行DMA读写
  12. Java:函数
  13. 使用newtonsoft序列化
  14. 如何用git上传代码到github详细步骤
  15. python的进程/线程/协程
  16. 读《移山之道——VSTS软件开发指南》
  17. 接口app 接口中上传 图片
  18. linux 关闭笔记本自带键盘
  19. pre 标签的使用注意事项
  20. PHP(六)PHP和HTML混合的一种形式

热门文章

  1. open和fopen的区别
  2. Objective-C学习笔记
  3. tachyon with hadoop
  4. GOF设计模式之1:单例设计模式
  5. Android进阶笔记19:onInterceptTouchEvent、onTouchEvent与onTouch
  6. VMware系统运维(十九)部署虚拟化桌面 Horizon View 5.2 通过手持设备进行连接测试
  7. java执行程序
  8. oracle数据操纵语言(DML)data manipulation language
  9. 初识 Asp.Net内置对象之Cookie对象
  10. highcharts设置Area颜色透明度