题目链接:http://codeforces.com/problemset/problem/557/D 大意 给出一个未必联通的无向图(点数至少为3),问最少加多少边可以形成一个奇圈,以及这样做的方案有多少种. 首先如果是一张没有边的图,那么直接就是需要加三条边,有C(n,3)种方式. 接着,判断这张图每一个联通块是否是一个二分图,因为二分图是一定没有奇圈的.如果有联通块不是二分图,那么也就是意味着存在奇圈,这样的话需要加0条边,方式为1种. 接下去还需要分两种情况讨论 1.如果所有的联通块都只…
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…
题目链接: 点这里 题目 D. Vitaly and Cycle 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…
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 the cycl…
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…
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…
题目大意:给出一个 n 点 m 边的图,问最少加多少边使其能够存在奇环,加最少边的情况数有多少种. 解题关键:黑白染色求奇环,利用数量分析求解. 奇环:含有奇数个点的环. 二分图不存在奇环.反之亦成立. #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<iostream> #include<cmath> using nam…
http://www.cnblogs.com/wenruo/p/4959509.html 给一个图(不一定是连通图,无重边和自环),求练成一个长度为奇数的环最小需要加几条边,和加最少边的方案数. 很容易知道连的边数只能是0,1,2,3. 如果是二分图一定不含长度为奇数的环. 难点是如果是二分图怎么求方案数呢? 二分图染色时能求出每一个联通块.在每一个联通块中把任意两个颜色相同的点连一条边即可达到要求. 如图中红色和绿色的边就是部分可行解 代码(含注释): /*******************…
题目链接 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…
poj 1236: 题目大意:给出一个有向图, 任务一: 求最少的点,使得从这些点出发可以遍历整张图  任务二: 求最少加多少边 使整个图变成一个强连通分量. 首先任务一很好做, 只要缩点 之后 求 入度为0的点 的个数就好了.   因为 缩点后无环,任何一个 入度不为0的点, 沿着入边 倒着走回去一定可以到达一个入度为0的点. 任务二: 首先给出结论: 如果整个图已经是一个强连通分量,那么答案是0.  否则求出 缩点后入度为0的点和出度为0的点的个数a,b, 答案就是 max(a,b). 今天…