一个矩阵,自乘无限次后能否全为正数?

如果n比较小,可以二分一下,但是这里n很大,乘一次都无法接受

可以考虑实际含义:矩阵看成邻接矩阵,那么0就是没有边,其余就是有边。

我们知道邻接矩阵自乘k次就相当于在原图走k步,无限次后是否有0?也就是图能否强连通。

判断就好,整个是环的情况题目限制不存在。

#include<iostream>
#include<cstdio> using namespace std; const int MAXN=; struct Edge{
int next,to;
}e[MAXN*MAXN*];
int ecnt,head[MAXN];
inline void add(int x,int y){
e[++ecnt].to = y;
e[ecnt].next = head[x];
head[x] = ecnt;
} inline int rd(){
int ret=,f=;char c;
while(c=getchar(),!isdigit(c))f=c=='-'?-:;
while(isdigit(c))ret=ret*+c-'',c=getchar();
return ret*f;
} int n; int bl[MAXN],cnt;
int ins[MAXN],sta[MAXN],top;
int dfn[MAXN],low[MAXN],tot;
void tarjan(int x){
dfn[x]=low[x]=++tot;ins[x]=;sta[++top]=x;
for(int i=head[x];i;i=e[i].next){
int v=e[i].to;
// cout<<x<<" "<<v<<endl<<endl;
if(!dfn[v]){
tarjan(v);
low[x]=min(low[x],low[v]);
}else if(ins[v]){
low[x]=min(low[x],dfn[v]);
}
}
if(dfn[x]==low[x]){
int elm;cnt++;
do{
elm = sta[top--];
ins[elm] = false;
bl[elm] = cnt;
}while(elm != x);
}
} int main(){
n=rd();int x;
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(rd()) add(i,j);
for(int i=;i<=n;i++) if(!dfn[i]) tarjan(i);
if(cnt!=) return puts("NO"),;
puts("YES");
return ;
}

[CF] 402 E. Strictly Positive Matrix的更多相关文章

  1. CodeForces 402 E Strictly Positive Matrix

    Strictly Positive Matrix 题解: 如果原来的 a[i][j] = 0, 现要 a[i][j] = 1, 那么等于 sum{a[i][k] + a[k][j]} > 1. ...

  2. Codeforces Round #236 (Div. 2)E. Strictly Positive Matrix(402E)

    E. Strictly Positive Matrix   You have matrix a of size n × n. Let's number the rows of the matrix f ...

  3. [CF #236 (Div. 2) E] Strictly Positive Matrix(强联通分量)

    题目:http://codeforces.com/contest/402/problem/E 题意:给你一个矩阵a,判断是否存在k,使得a^k这个矩阵全部元素都大于0 分析:把矩阵当作01矩阵,超过1 ...

  4. CF402E Strictly Positive Matrix 传递闭包用强连通分量判断

    题目链接:http://codeforces.com/problemset/problem/402/E /**算法分析: 这道题考察了图论基本知识,就是传递闭包,可以构图用强联通分量来判断 */ #i ...

  5. codeforces 402E - Strictly Positive Matrix【tarjan】

    首先认识一下01邻接矩阵k次幂的意义:经过k条边(x,y)之间的路径条数 所以可以把矩阵当成邻接矩阵,全是>0的话意味着两两之间都能相连,也就是整个都要在一个强连通分量里,所以直接tarjan染 ...

  6. CF402E Strictly Positive Matrix(矩阵,强联通分量)

    题意 给定一个 n∗n 的矩阵 A,每个元素都非负判断是否存在一个整数 k 使得 A^k 的所有元素 >0 n≤2000(矩阵中[i][i]保证为1) 题解 考虑矩阵$A*A$的意义 ,设得到的 ...

  7. http://codeforces.com/contest/402/problem/E

    E. Strictly Positive Matrix time limit per test 1 second memory limit per test 256 megabytes input s ...

  8. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.5.10

    Every $k\times k$ positive matrix $A=(a_{ij})$ can be realised as a Gram matrix, i.e., vectors $x_j$ ...

  9. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]Contents

    I find it may cost me so much time in doing such solutions to exercises and problems....I am sorry t ...

随机推荐

  1. hdu1162 Eddy's picture 基础最小生成树

    #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> # ...

  2. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) B

    Description Bear Limak examines a social network. Its main functionality is that two members can bec ...

  3. ADB over Wi-Fi

    ADB over Wi-Fi 1.root $adb root 2.设置tcp端口并重启tcpip服务 $adb shell setprop persist.adb.tcp.port &&am ...

  4. 123 Best Time to Buy and Sell Stock III 买卖股票的最佳时机 III

    假设你有一个数组,它的第 i 个元素是一支给定的股票在第 i 天的价格.设计一个算法来找到最大的利润.你最多可以完成两笔交易.注意:你不可同时参与多笔交易(你必须在再次购买前出售掉之前的股票).详见: ...

  5. 17984 FFF团的怒火

    17984 FFF团的怒火 该题有题解 时间限制:1000MS  内存限制:65535K提交次数:55 通过次数:3 收入:3 题型: 编程题   语言: G++;GCC;VC;JAVA Descri ...

  6. ping localhost出现地址::1

    近期发现本机的localhost不好用了. 症状: 自己本机部署服务器时,浏览器地址栏访问localhost:8080不通: 禁用网络连接,未果: 拔出网线,OK. cmd里ping之,返回结果如下: ...

  7. Jenkins视图使用--添加删除视图

    job建立的特别多的时候,我们可能不太容易找到自己的某个job,这时,我们就可以在Jenkins中建立视图.job的视图类似于我们电脑上的文件夹.可以通过一些过滤规则,将已经建好的job过滤到视图中, ...

  8. 通用mapper的generator

    <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-genera ...

  9. log4j 日志分级处理

    log4j 配置文件: log4j.rootLogger=debug,stdout,debug,info,errorlog4j.appender.stdout=org.apache.log4j.Con ...

  10. php用面向对象从mysql取数据

    <?php //建立数据库的链接@$_mysqli = new mysqli('localhost','root','123456','dbname');if(mysqli_connect_er ...