Codeforces - 1020B Badge(找环)】的更多相关文章

Medicine faculty of Berland State University has just finished their admission campaign. As usual, about 80%80% of applicants are girls and majority of them are going to live in the university dormitory for the next 44 (hopefully) years. The dormitor…
题意: 以每个点为起点,找到第一个出现两次的点 解析: 我是先找出来所有的环  环上的点找出来的肯定是自己 bz[i]  = i; 然后去遍历不在环上的点j  如果通过这个点找到一个已经标记的的点i  那么bz[j] = bz[i]; 行吧...其实直接暴力 就几行代码...真是的...过分....我真是垃圾啊..啦啦啦...呸.. #include <bits/stdc++.h> using namespace std; , INF = 0x7fffffff; vector<int&g…
题目链接:http://codeforces.com/problemset/problem/117/C C. Cycle time limit per test 2.5 seconds memory limit per test 256 megabytes input standard input output standard output A tournament is a directed graph without self-loops in which every pair of ve…
题目链接:http://codeforces.com/problemset/problem/711/D D. Directed Roads time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder and Chris the Baboon has explored Udayland for quite some…
[题目]D. Almost Acyclic Graph [题意]给定n个点的有向图(无重边),问能否删除一条边使得全图无环.n<=500,m<=10^5. [算法]拓扑排序 [题解]找到一个简单环,则欲删除的边一定经过该环.尝试环上的每一条边(至多n条边)后再次拓扑排序判断全图是否有环. 拓扑排序后定位到简单环:剩余图是环+环内DAG,DFS过程中将走入死路的点标-1,访问过标1,找到访问过的点就是简单环.换起始点直到找到环为止. 复杂度O(nm). #include<cstdio>…
<题目链接> 题目大意: 给定一个$n$条边,$n$个点的图,每个点只有一条出边(初始状态),现在能够任意对图上的边进行翻转,问你能够使得该有向图不出先环的方案数有多少种. 解题分析: 很明显本题需要对环的部分和链的部分分开进行讨论,对于环的部分,能够使得该环不为有向环的方案数有$2^k-2$种($k$为环上的点数,相当于减去环上所有边都是顺时针和逆时针情况),对于链的部分,方案数就是$2^k$($k$为链上的点数).因为初始状态每个点只有一条出边,所以即使存在环,也一定是简单环(即不存在环套…
New Reform time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected b…
4191: 无向图找环 Time Limit: 5 Sec  Memory Limit: 128 MB Submit: 117  Solved: 34 Description 给你一副无向图,每条边有边权,保证图联通,现在让你判断这个图是否有异或值大于零的环存在. Input 多组测试数据,每组先输入两个数n m,表示图的点跟边的数量. 然后是m行,每行三个数a b c.代表一条边的起点,终点,边权. 1 <= n<= 100000, 1 <= m <= 200000. 1 <…
题意: 就是找出所有环的个数, 但这个环中的每个点都必须只在一个环中 解析: 在找环的过程中 判断度数是否为2就行...emm... #include <bits/stdc++.h> using namespace std; , INF = 0x7fffffff; int n, m, s, t, flag; vector<int> G[maxn]; int vis[maxn], res; void dfs(int u, int fa) { vis[u] = ; ; i<G[u…
http://acm.sgu.ru/problem.php?contest=0&problem=219 题目大意: 如果指向某个点的边权全都为正数,那么这个点就是可点燃的,点燃操作把入弧权值-1,出弧权值都+1, 如果在某种点燃序列之后还可以再点燃一些点使得这个点还可以点燃,那么这个点在这种点燃序列之后存活 如果在任何点燃序列之后都还可以再点燃一些点使得这个点还可以点燃,那么这个点可存活 现在求所有点是否可存活 思路: 考虑不可存活的点:对于某个状态,对于不可存活的点,要想使得没有序列可以使它被…