Codeforces 1093D(染色+组合数学)】的更多相关文章

题面 传送门 题目大意:给出一个无向图,每个节点可以填1,2,3三个数中的一个 问有多少种填数方案,使两个相邻节点的数之和为奇数 分析 如果图中有奇环,一定无解 我们对图黑白染色,由于图可能不联通,记第i个连通分量的黑点数量为\(b_i\),白点数量为\(w_i\) 观察发现每一条边的连接的两个节点,一个是2,另一个是1或3 显然要不黑点全部填2,要不白点全部填2 若黑点填2,则剩下的白点有\(2^{w_i}\) 种填法 若白点填2,则剩下的黑点有\(2^{b_i}\) 种填法 总答案为: \[…
D - Beautiful Graph CodeForces - 1093D You are given an undirected unweighted graph consisting of nn vertices and mm edges. You have to write a number on each vertex of the graph. Each number should be 11, 22or 33. The graph becomes beautiful if for…
题目链接:Beautiful Graph 题意:给定一张无向无权图,每个顶点可以赋值1,2,3,现要求相邻节点一奇一偶,求符合要求的图的个数. 题解:由于一奇一偶,需二分图判定,染色.判定失败,直接输出0.成功的话,统计下奇数(cnt1)和偶数(cnt2)顶点个数,只有奇数有两种,也就是说有$2^{cnt1}$种,但是可以把奇数和偶数顶点翻转,奇变偶,偶变奇,即最后有$2^{cnt1}+2^{cnt2}$种,注意此图可能不连通,各个图之间的答案数要相乘. #include <set> #inc…
<题目链接> 题目大意: 给你一个无向图(该无向图无自环,且无重边),现在要你给这个无向图的点加权,所加权值可以是1,2,3.给这些点加权之后,要使得任意边的两个端点权值之和为奇数,问总共有多少种可能?结果mod 998244353. 解题分析: 整张图的所有顶点赋权之后,一定分为奇.偶两部分点集,并且,要想使的该图满足条件,任意边的两个端点的奇偶性应该是不同的,所以我们可以用DFS对图进行二分图染色,将图分为两个部分,需要注意的是,该图未必连通.然后就是DFS的过程中,如果下一个点已经染过色…
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard. There are nn bricks lined in a row on the ground. Chouti has got mm paint buckets of different colors at hand, so he painted each brick in on…
Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by the fear of the wolf, but…
题意:给定无向图,让你给点加权(1,2,3),使得每条边是两端点点权和维奇数. 思路:一个连通块是个二分图,判定二分图可以dfs,并查集,2-sat染色. 这里用的并查集(还可以带权并查集优化一下,或者干脆用dfs). 计数的时候每个连通块单独考虑,我们从连通块的第一个点开始dfs,如果是该填奇数点,那么当前方案数*=2:分第一个点奇偶两种情况即可. (多组输入一定注意初始化,这次CF多组输入好坑啊... #include<bits/stdc++.h> #define ll long long…
Acingel is a small town. There was only one doctor here — Miss Ada. She was very friendly and nobody has ever said something bad about her, so who could've expected that Ada will be found dead in her house? Mr Gawry, world-famous detective, is appoin…
H - Benches Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south pa…
A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≤ i ≤ n) such that pi = i. Your task is t…