E. Reachability from the Capital dfs暴力】的更多相关文章

E. Reachability from the Capital 这个题目就是给你一个有向图,给你起点,问增加多少条边让这个图变成一个连通图. 这个因为n只有5000m只有5000 所以可以暴力枚举这个n,用n*n的复杂度过去. #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <stack> #include <bits…
FZU 2107 Hua Rong Dao Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u  Practice  Description Cao Cao was hunted down by thousands of enemy soldiers when he escaped from Hua Rong Dao. Assuming Hua Rong Dao is a narrow aisl…
Board Game Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u  Gym 100935G Description standard input/outputStatements Feras bought to his nephew Saleem a new game to help him learning calculating. The game consists of a boa…
Problem Description These few days, Baby Ming is addicted to playing a matrix game. Given a n∗m matrix, the character ,j∗) (i,j=,,...) are the numbers between −. There are an arithmetic sign (‘+’, ‘-‘, ‘∗’, ‘/’) between every two adjacent numbers, ot…
Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried despe…
E - Reachability from the Capital  CodeForces - 999E 题目链接:https://vjudge.net/contest/236513#problem/E 大意:给你n条边的关系,输入的第一个只指向第一个,然后让你判断要想从指定的点到达剩下的所有的点,问你最少需要添加多少条边才符合要求. 思路:首先使用tarjan算法进行染色,缩点.到最后判断 缩减后 入度为零的不含有城市中心的强连通子图的个数就可以了!!! 原因,染完色之后,如果有入度为0的强连…
1008 选数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知 n 个整数 x1,x2,…,xn,以及一个整数 k(k<n).从 n 个整数中任选 k 个整数相加,可分别得到一系列的和.例如当 n=4,k=3,4 个整数分别为 3,7,12,19 时,可得全部的组合与它们的和为: 3+7+12=22 3+7+19=29 7+12+19=38 3+12+19=34. 现在,要求你计算出和为素…
求联通分量个数,在dfs一次 #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <cstdlib> #include <iomanip> #include <cmath…
B. Equivalent Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/problem/B Description Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are…
题意:给一个的格子图,有 n 行单元格,每行有a[i]个格子,要求往格子中填1~m的数字,要求每个数字大于等于左边的数字,大于上边的数字,问有多少种填充方法. 析:感觉像个DP,但是不会啊...就想暴力试试,反正数据量看起来不大才7,但是...TLE了,又换了一个暴力方法,2秒多过了,差点啊. 其实这是一个状压DP,dp[i][s]表示在第 i 列,在集合 s 中有方法数,那么怎么转移呢,这个还是挺简单的,就是判断第i+1列是不是比第 i 列都大于等于就ok了, 输入时先把行,转化成列,再计算,…