题目链接 n个点, m条边, 问最少加几条边可以出现一个奇环, 在这种情况下, 有多少种加边的方式. 具体看代码解释 #include<bits/stdc++.h> using namespace std; #define pb(x) push_back(x) #define ll long long #define mk(x, y) make_pair(x, y) #define lson l, m, rt<<1 #define mem(a) memset(a, 0, sizeo…
Vitaly and Cycle time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles…
http://www.cnblogs.com/wenruo/p/4959509.html 给一个图(不一定是连通图,无重边和自环),求练成一个长度为奇数的环最小需要加几条边,和加最少边的方案数. 很容易知道连的边数只能是0,1,2,3. 如果是二分图一定不含长度为奇数的环. 难点是如果是二分图怎么求方案数呢? 二分图染色时能求出每一个联通块.在每一个联通块中把任意两个颜色相同的点连一条边即可达到要求. 如图中红色和绿色的边就是部分可行解 代码(含注释): /*******************…
题意简述 给定一个图 求至少添加多少条边使得它存在奇环 并求出添加的方案数 (注意不考虑自环) ----------------------------------------------------------------------------- 一道二分图染色的讨论题 比赛时只会用二分图染色判断树以及偶环 忘记用这个来判奇环... 二分图染色这种联赛知识点的题目现在也不会写了... ------------------------------------------------------…
<题目链接> 题目大意: 给你一个无向图(该无向图无自环,且无重边),现在要你给这个无向图的点加权,所加权值可以是1,2,3.给这些点加权之后,要使得任意边的两个端点权值之和为奇数,问总共有多少种可能?结果mod 998244353. 解题分析: 整张图的所有顶点赋权之后,一定分为奇.偶两部分点集,并且,要想使的该图满足条件,任意边的两个端点的奇偶性应该是不同的,所以我们可以用DFS对图进行二分图染色,将图分为两个部分,需要注意的是,该图未必连通.然后就是DFS的过程中,如果下一个点已经染过色…
题目链接:Beautiful Graph 题意:给定一张无向无权图,每个顶点可以赋值1,2,3,现要求相邻节点一奇一偶,求符合要求的图的个数. 题解:由于一奇一偶,需二分图判定,染色.判定失败,直接输出0.成功的话,统计下奇数(cnt1)和偶数(cnt2)顶点个数,只有奇数有两种,也就是说有$2^{cnt1}$种,但是可以把奇数和偶数顶点翻转,奇变偶,偶变奇,即最后有$2^{cnt1}+2^{cnt2}$种,注意此图可能不连通,各个图之间的答案数要相乘. #include <set> #inc…
题目大意:给出一个 n 点 m 边的图,问最少加多少边使其能够存在奇环,加最少边的情况数有多少种. 解题关键:黑白染色求奇环,利用数量分析求解. 奇环:含有奇数个点的环. 二分图不存在奇环.反之亦成立. #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<iostream> #include<cmath> using nam…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles of an odd length in w…
D. Vitaly and Cycle       time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked th…
D. Vitaly and Cycle Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/problem/D Description After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles of an…