poj3411Paid Roads(dfs)】的更多相关文章

链接 想偷点懒用矩阵存 一直WA 后来看讨论说有重边改为邻接表 这题边可能走了不止一次 我设的最多两次可过 #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stdlib.h> using namespace std; #define INF 0xfffffff struct node { int u,v,w1,w2,d,next…
D. 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 from 1to n. There are n directed roads in the Udayland. i-th of them goes from town i to some other tow…
题目链接:D Directed Roads 题意:给出n个点和n条边,n条边一定都是从1~n点出发的有向边.这个图被认为是有环的,现在问你有多少个边的set,满足对这个set里的所有边恰好反转一次(方向反转),使得这个图里没有环. 思路:感觉关键是,n个点n条边,且每个点的出度为1,所以图里一定没有复环.想要使图里没环,对于每个连通块(点数为i)里的环(如果有环 点数为j),只要不是全翻和全不翻都是满足题意的set, 一共满足题意得set  即为 2^(i-j) * (2^j-2).所有的连通块…
题目链接: 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…
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 ntowns numbe…
Description Once upon a time there was a strange kingdom, the kingdom had n cities which were connected by n directed roads and no isolated city.One day the king suddenly found that he can't get to some cities from some cities.How amazing!The king is…
题目链接: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…
Time Limit: 0.5 second(s) Memory Limit: 32 MB Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Dhaka Division decided to keep up with new trends. Formerly all …
题目链接 点和边 都很少,确定一个界限,爆搜即可.判断点到达注意一下,如果之前已经到了,就不用回溯了,如果之前没到过,要回溯. #include <cstring> #include <cstdio> #include <string> #include <iostream> #include <algorithm> #include <vector> #include <queue> using namespace st…
题目链接:http://codeforces.com/problemset/problem/711/D 给你一个n个节点n条边的有向图,可以把一条边反向,现在问有多少种方式可以使这个图没有环. 每个连通量必然有一个环,dfs的时候算出连通量中点的个数y,算出连通量的环中点的个数x,所以这个连通量不成环的答案是2^(y - x) * (2^x - 2). 最后每个连通量的答案相乘即可. //#pragma comment(linker, "/STACK:102400000, 102400000&q…