CodeForces 711D Directed Roads】的更多相关文章

ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of n towns numbered from1 to n. There are n directed roads in the Udayland. i-th of them goes from town i to some other town ai (ai ≠ i). ZS th…
题目链接:http://codeforces.com/problemset/problem/711/D 思路:由于每个点出度都为1,所以没有复杂的环中带环.DFS遍历,若为环则有2^k-2种,若为链则为2^k种. #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+10; const int mod=1e9+7; int v[N],vis[N],num,times[N],c[N];…
题目链接: http://codeforces.com/problemset/problem/711/D 题目大意: 给一张N个点N条有向边的图,边可以逆向.问任意逆向若干条边使得这张图无环的方案数(mod 1e9+7). 题目思路: [图论] 因为是N条边所以不会有复杂的环,最多只会有若干组一个环加一条链. 推算得到,一个大小为k的环对答案的贡献是*(2k-2),而长度为k的链对答案的贡献是2k(链不包括环上的) 用dfs找出每一组环的大小和链的长度,计算答案即可. // //by coolx…
题意:给定一个有向图,然后你可能改变某一些边的方向,然后就形成一种新图,让你求最多有多少种无环图. 析:假设这个图中没有环,那么有多少种呢?也就是说每一边都有两种放法,一共有2^x种,x是边数,那么如果有环呢?假设x是这个连通块的边数, y是这个环的边数,那么就一共有2^x * (2 ^ y - 2) 种,减去这两种就是一边也不变,和所有的边都就变,这样就形成环了. 那么怎么计算呢?这个题的边很特殊,所以我们可以利用这个特征,我们在每个连通块时,用vis记录一下开始的父结点,用cnt记录每一个到…
计数,模拟. 首先观察一下给出的图的特点: $1.$一定存在环. $2.$可能存在多个环. 我们对每个环计算方案数,假设环$C$上包含$x$条边,那么把环$C$破坏掉的方案数有${2^x} - 2$种. 那么答案就是每个环的方案数乘起来,再乘上${2^p}$,$p$表示不在环上的边的条数. 找环的话模拟一下就可以了. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #inclu…
<题目链接> 题目大意: 给定一个$n$条边,$n$个点的图,每个点只有一条出边(初始状态),现在能够任意对图上的边进行翻转,问你能够使得该有向图不出先环的方案数有多少种. 解题分析: 很明显本题需要对环的部分和链的部分分开进行讨论,对于环的部分,能够使得该环不为有向环的方案数有$2^k-2$种($k$为环上的点数,相当于减去环上所有边都是顺时针和逆时针情况),对于链的部分,方案数就是$2^k$($k$为链上的点数).因为初始状态每个点只有一条出边,所以即使存在环,也一定是简单环(即不存在环套…
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 time. They realize that it consists of n towns numb…
题目链接: 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 time. They realize that it consists of n town…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of n towns numbered from 1 to n. Ther…
ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of n towns numbered from 1 to n. There are n directed roads in the Udayland. i-th of them goes from town i to some other town ai (ai ≠ i). ZS t…