首先我们可以确认 1的值一定是0

题目要求的是 有边的两个点所代表的值二进制有一位不同(即有边相连的两个值二进制所包含的1的个数相差为1)

所以我们通过他给你的图进行BFS 把原图分为一圈一圈的 并且先给每一个点赋一个初值

这样每一圈内的值二进制所包含的1的个数往外递增且同一圈内值二进制所包含的1的个数是相等的 目前我们就得到了题目的一个可行解

题目追加要求最小字典序 我们发现把这2^n个数二进制表示出来 则有n列 任意两列之间的交换是不会影响值二进制中1的个数且符合边关系的

即交换二进制中的任意两列不会影响答案的正确性

所以我们就可以通过排列这个二维数组的字典序来得到 答案的最小字典序

#include<bits/stdc++.h>
using namespace std; inline void splay(int &v)
{
v = ;
char c = ;
int p = ;
while (c < '' || c > '')
{
if (c == '-')
{
p = -;
}
c = getchar();
}
while (c >= '' && c <= '')
{
v = (v << ) + (v << ) + c - '';
c = getchar();
}
v *= p;
}
const int N = ;
int n, m, dp[N], q[N], fir[N], sz, to[], nxt[], vis[N], inque[N];
struct Q
{
bool s[N];
int id;
} f[];
void add(int x, int y)
{
nxt[++sz] = fir[x], fir[x] = sz, to[sz] = y;
}
bool cmp(Q a, Q b)
{
for (int i = ; i <= ( << n); i++)
{
if (a.s[i] != b.s[i])
{
return a.s[i] > b.s[i];
}
}
return true;
}
int main()
{
#ifdef CX_TEST
freopen("E:\\program--GG\\test_in.txt", "r", stdin);
#endif
int T;
cin >> T;
while (T--)
{
cin >> n >> m;
for (int i = ; i <= ( << n); i++)
{
inque[i] = vis[i] = fir[i] = dp[i] = ;
}
sz = ;
for (int i = , u, v; i <= m; i++)
{
splay(u), splay(v);
add(u, v), add(v, u);
}
for (int i = ; i <= ( << n); i++)
{
dp[i] = ;
}
int t = ;
vis[] = ;
int hd = , tl = ;
for (int u = fir[]; u; u = nxt[u])
{
dp[to[u]] = << (t++);
q[++tl] = to[u];
}
while (hd != tl)
{
int v = q[++hd];
vis[v] = ;
for (int u = fir[v]; u; u = nxt[u])
{
if (!vis[to[u]])
{
dp[to[u]] |= dp[v];
if (!inque[to[u]])
{
q[++tl] = to[u];
inque[to[u]] = ;
}
}
}
}
for (int i = ; i < n; i++)
{
f[i].id = i;
}
for (int i = ; i <= ( << n); i++)
{
for (int j = ; j < n; j++)
{
f[j].s[i] = dp[i] >> j & ;
}
}
sort(f, f + n, cmp);
for (int i = ; i <= ( << n); i++)
{
int ret = ;
for (int j = ; j < n; j++)
{
if (f[j].s[i])
{
ret |= ( << j);
}
}
printf("%d%c", ret, " \n"[i == ( << n)]);
}
}
}

牛客国庆集训派对Day5 A.璀璨光滑的更多相关文章

  1. 2019牛客国庆集训派对day5

    2019牛客国庆集训派对day5 I.Strange Prime 题意 \(P=1e10+19\),求\(\sum x[i] mod P = 0\)的方案数,其中\(0 \leq x[i] < ...

  2. 牛客国庆集训派对Day5 Solution

    A    璀璨光滑 留坑. B    电音之王 蒙特马利大数乘模运算 #include <bits/stdc++.h> using namespace std; typedef long ...

  3. 牛客国庆集训派对Day5 数论之神

    题目描述 终于活成了自己讨厌的样子. 这是她们都还没长大的时候发生的故事.那个时候,栗子米也不需要为了所谓的爱情苦恼. 她们可以在夏日的午后,花大把的时间去研究生活中一些琐碎而有趣的事情,比如数论. ...

  4. 牛客国庆集训派对Day6 A Birthday 费用流

    牛客国庆集训派对Day6 A Birthday:https://www.nowcoder.com/acm/contest/206/A 题意: 恬恬的生日临近了.宇扬给她准备了一个蛋糕. 正如往常一样, ...

  5. 牛客国庆集训派对Day1 L-New Game!(最短路)

    链接:https://www.nowcoder.com/acm/contest/201/L 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...

  6. 牛客国庆集训派对Day4 J-寻找复读机

    链接:https://www.nowcoder.com/acm/contest/204/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...

  7. 牛客国庆集训派对Day4 I-连通块计数(思维,组合数学)

    链接:https://www.nowcoder.com/acm/contest/204/I 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...

  8. 牛客国庆集训派对Day1-C:Utawarerumono(数学)

    链接:https://www.nowcoder.com/acm/contest/201/C 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...

  9. 牛客国庆集训派对Day2 Solution

    A    矩阵乘法 思路: 1° 牛客机器太快了,暴力能过. #include <bits/stdc++.h> using namespace std; #define N 5000 in ...

随机推荐

  1. Python--偏函数(Partial)

    Python--偏函数(Partial)   出处  https://blog.csdn.net/Appleyk/article/details/77609114 一.什么是偏函数? (1)在Pyth ...

  2. redis的坑

    1.外网无法连接redis 解决方法: 把redis.conf里的bind 127.0.0.1注释掉,不行的话把127.0.0.1修改成0.0.0.0 2.make的时候显示没有gcc 解决方法: 安 ...

  3. BCP 数据导出

    EXEC master..xp_cmdshell 'BCP test.dbo.name out d:\t_002.txt -c -t -T' EXEC master..xp_cmdshell 'BCP ...

  4. URL库函数

    1.urlopen from urllib import request resp=request urlopen('http://www.baidu.com') print(resp.read()) ...

  5. Leetcode之广度优先搜索(BFS)专题-752. 打开转盘锁(Open the Lock)

    Leetcode之广度优先搜索(BFS)专题-752. 打开转盘锁(Open the Lock) BFS入门详解:Leetcode之广度优先搜索(BFS)专题-429. N叉树的层序遍历(N-ary ...

  6. 华为HCNA乱学Round 7:VLAN间路由

  7. selenium—显示等待中期望的场景语句

    ① alert_is_present() 判断页面是否出现alert框 wait = WebDriverWait(driver,10) alert = wait.until(EC.alert_is_p ...

  8. flask_script

    Flask Script扩展提供向Flask插入外部脚本的功能,包括运行一个开发用的服务器,一个定制的Python shell,设置数据库的脚本,cronjobs,及其他运行在web应用之外的命令行任 ...

  9. 2.更新YUM源

    查看本地源 先删除本地所有源 下载源仓库文件,xxx.repo curl -o /etc/yum.repos.d/ali.repo http://mirrors.aliyun.com/repo/Cen ...

  10. windows10 AppStore安装 应用商店重新安装

    点击左下角的搜索按钮,如下图所示   输入powershell,在结果中找到widows powershell应用,如下图所示   右键单击widows powershell应用,选择以管理员运行,如 ...