2015 多校赛 第二场 1006 (hdu 5305)
For each testcase, the first line contains two integers n (1≤n≤8) and m (0≤m≤n(n−1)2), indicating the number of people and the number of pairs of friends, respectively. Each of the next m lines contains two numbers x and y, which mean x and y are friends. It is guaranteed that x≠y and every friend relationship will appear at most once.
题意:给出一幅无向图。依次对边染白色或黑色,使得每个点所关联的白边和黑边数目相同。问有多少种染色方法。
思路:
搜索题。强行暴力搜必定超时。枚举点来搜索也不好写。因此枚举边。
记录每个点的度数,若有点的度数为奇数,直接输出0。否则,将所有点的度数除以2,得到每个点关联的白边数目和黑边数目,此为剪枝。
代码如下:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int t,n,m,a[],b[],d[];
int B[],W[],ans;
void dfs(int k){
if(k==m){
ans++;return;
}
int u=a[k],v=b[k];
if(B[u]<d[u]&&B[v]<d[v]){
B[u]++,B[v]++;
dfs(k+);
B[u]--,B[v]--;
}
if(W[u]<d[u]&&W[v]<d[v]){
W[u]++,W[v]++;
dfs(k+);
W[u]--,W[v]--;
}
}
int main(){
scanf("%d",&t);
while(t--){
bool flag=true;
scanf("%d%d",&n,&m);
memset(d,,sizeof(d));
for(int i=;i<m;i++){
scanf("%d%d",&a[i],&b[i]);
d[a[i]]++;d[b[i]]++;
}
for(int i=;i<=n;i++){
if(d[i]&)
flag=false;
d[i]/=;
}
if(!flag){
puts("");
continue;
}
memset(W,,sizeof(W));
memset(B,,sizeof(B));
ans=;
dfs();
printf("%d\n",ans);
}
return ;
}
2015 多校赛 第二场 1006 (hdu 5305)的更多相关文章
- 2015 多校赛 第二场 1004 hdu(5303)
Problem Description There are n apple trees planted along a cyclic road, which is L metres long. You ...
- 2015 多校赛 第二场 1002 (hdu 5301)
Description Your current task is to make a ground plan for a residential building located in HZXJHS. ...
- 2015 多校赛 第一场 1007 (hdu 5294)
总算今天静下心来学算法.. Description Innocent Wu follows Dumb Zhang into a ancient tomb. Innocent Wu’s at the e ...
- 2015 多校赛 第一场 1002 (hdu 5289)
Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n ...
- 2015 多校赛 第一场 1001 (hdu 5288)
Description OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l&l ...
- 2019HDU多校赛第二场 H HDU 6598 Harmonious Army(最小割模型)
参考博客https://blog.csdn.net/u013534123/article/details/97142191 #include<bits/stdc++.h> using na ...
- 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)
以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...
- SCNU省选校赛第二场B题题解
今晚的校赛又告一段落啦,终于"开斋"了! AC了两题,还算是满意的,英语还是硬伤. 来看题目吧! B. Array time limit per test 2 seconds me ...
- HDU 5305 Friends (搜索+剪枝) 2015多校联合第二场
開始对点搜索,直接写乱了.想了想对边搜索,尽管复杂度高.剪枝一下水过去了. 代码: #include<cstdio> #include<iostream> #include&l ...
随机推荐
- js案例分析
名字取的高大上,其实只是我平时上网浏览遇到的一些我感觉还不错的小题目,再加上我或者是我在网上找到的一些理解,就保存到这里了. 2019/4/2 最新开了个新坑,是一个javascipt30的一些案例 ...
- linux常用命令--ubuntu
linux 操作系统 一.linux 操作系统概述 二.安装linux系统 三.linux系统环境 ubuntu,默认有6个命令交互通道和一个图形界面交互通道,默认进入到的是图形界面通道 命令交互模式 ...
- btrfs基础
btrfs文件系统简介 btrfs文件系统:技术预览版(Centos7) Btrfs(B-tree.Butter FS.Better FS),GPL授权,Orale2007提出是想用来取代Ext文 ...
- linux - redis基础
目录 linux - redis基础 redis 源码编译安装 redis 数据结构 1. strings类型 2. list 类型 3. sets集合类型 有序集合 5. 哈希数据结构 centos ...
- 【郑轻邀请赛 B】base64解密
[题目链接]:https://acm.zzuli.edu.cn/zzuliacm/problem.php?id=2128 [题意] [题解] 把密文; 在表中找到每个字符对应的数字; 然后转换成相应的 ...
- qwb VS 去污棒
qwb VS 去污棒 Time Limit: 2 Sec Memory Limit: 256 MB Description qwb表白学姐失败后,郁郁寡欢,整天坐在太阳底下赏月.在外人看来,他每天自 ...
- 网站配置https(腾讯云域名操作)
我们都知道http协议是超文本传输协议,早期的网站使用的都是http,但是并不安全,数据在传输过程中容易被拦截篡改.所以后面有了https,也就是经过ssl加密的http协议.本文主要对网站配置htt ...
- python 执行环境
一些函数 执行其它非python程序 1 一些函数 callable callable()是一个布尔函数,确定一个对象是否可以通过函数操作符(())来调用.如果函数可调用便返回True,否则便是Fal ...
- PHP array_intersect_uassoc()
定义和用法 array_intersect_uassoc() 函数使用用户自定义的回调函数计算数组的交集,用回调函数比较索引. array_intersect_uassoc() 返回一个数组,该数组包 ...
- 用于改善质量、稳定性和多样性的可增长式GAN
用于改善质量.稳定性和多样性的可增长式GAN GANs NVIDIA Fly real or fake ? real or fake ? 1024 x 1024 images generated us ...