Codeforces Round #236 (Div. 2) E. Strictly Positive Matrix
来源:互联网 发布:js中window.open 编辑:程序博客网 时间:2024/04/30 23:54
You have matrix a of size n × n. Let's number the rows of the matrix from 1 to n from top to bottom, let's number the columns from 1 to n from left to right. Let's use aij to represent the element on the intersection of the i-th row and the j-th column.
Matrix a meets the following two conditions:
- for any numbers i, j (1 ≤ i, j ≤ n) the following inequality holds: aij ≥ 0;
- .
Matrix b is strictly positive, if for any numbers i, j (1 ≤ i, j ≤ n) the inequality bij > 0 holds. You task is to determine if there is such integer k ≥ 1, that matrix ak is strictly positive.
The first line contains integer n (2 ≤ n ≤ 2000) — the number of rows and columns in matrix a.
The next n lines contain the description of the rows of matrix a. The i-th line contains n non-negative integers ai1, ai2, ..., ain (0 ≤ aij ≤ 50). It is guaranteed that .
If there is a positive integer k ≥ 1, such that matrix ak is strictly positive, print "YES" (without the quotes). Otherwise, print "NO" (without the quotes).
21 00 1
NO
54 5 6 1 21 2 3 4 56 4 1 2 41 1 1 1 14 4 4 4 4
YES
图论知识,一张图的邻接矩阵描述了点与点之间的可达关系,其k次幂表示了长度为k的路径的可达性。很明确,如果存在题目要求的k,即任意两点可达,a^k 就是一张有向完全图。
解法:
图的任意点的可达性算法比较多,稍微列于下...
Floyd算法:三个循环,求解图的最短路算法,O(n^3)。
Warshall 算法:求解二元关系的传递闭包,和Floyd算法有点类似,O(n^3)。可以尝试把矩阵变成布尔矩阵,利用位运算加速计算,貌似亦可解决此题。
然而,如果仅仅纠结于可达性,这道题就基本卡死了。因为可达性算法多数都是O(n^3),再怎么剪枝优化也几乎超时。因此,需要考虑有向完全图。
既然a^k 是有向完全图,那么对于a应该是有且仅有一个强连通分量,tarjan算法,O(|V|+|E|),over.
总结来说:tarjan算法是深度优先搜索算法,其结果只是强联通关系,信息量少,复杂度相对较低。而可达性算法,对每两个点之间的可达性都需要做出描述,信息量大,复杂度高,因此从这一点来说,解决一个问题可以从信息量的角度去选择比较合适的算法。
- Codeforces Round #236 (Div. 2) E. Strictly Positive Matrix
- Codeforces Round #236 (Div. 2) E. Strictly Positive Matrix 强连通
- CodeForces 402E Strictly Positive Matrix
- Strictly Positive Matrix CodeForces
- [矩阵乘法转图论 强连通] Codeforces 403C #236 (Div. 1) C. Strictly Positive Matrix
- CF DIV2 236E Strictly Positive Matrix(强连通)
- CF(Strictly Positive Matrix) 强连通分量
- cf 236 div2 E Strictly Positive Matrix 矩阵阶乘和图上路径(计数)(可达)(最优值)问题
- Codeforces Round #213 (Div. 2) C Matrix
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces Round #103 (Div. 2) E题
- Codeforces Round #147 (Div. 2) E
- Codeforces Round #184 (Div. 2) D、E
- Codeforces Round #197 (Div. 2) (C~E)
- Codeforces Round #102 (Div. 2) //缺E
- Codeforces Round #104 (Div. 2) //缺E
- Codeforces Round #105 (Div. 2) //缺E
- Codeforces Round #103 (Div. 2) //缺E
- C/C++中算法运行时间的三种计算方式
- java中equals() 和“==”的比较
- 获取年月日和星期
- KeySet() 和 EntrySet()
- treeview控件能用的从sql数据源到HierarchicalDataSourceControl数据源转换器
- Codeforces Round #236 (Div. 2) E. Strictly Positive Matrix
- LInux下可以使用命令自动与网络的NTP服务器同步时间 CSDN验证码验证失败问题解决
- linux的<pthread.h>
- python 将任意基本类型转化为String型
- [NLP]Introduction
- UML---statechart diagram
- 关于在做绕开SafeSEH的一个实验时(章节:11.6)一个神奇的事情
- python判断字符串
- Fatal signal 11 (SIGSEGV) at 0x00000048 (code=1)