HDU 2767.Proving Equivalences-强连通图(有向图)+缩点
Proving Equivalences
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9208 Accepted Submission(s): 3257
Let A be an n × n matrix. Prove that the following statements are equivalent:
1. A is invertible.
2. Ax = b has exactly one solution for every n × 1 matrix b.
3. Ax = b is consistent for every n × 1 matrix b.
4. Ax = 0 has only the trivial solution x = 0.
The typical way to solve such an exercise is to show a series of implications. For instance, one can proceed by showing that (a) implies (b), that (b) implies (c), that (c) implies (d), and finally that (d) implies (a). These four implications show that the four statements are equivalent.
Another way would be to show that (a) is equivalent to (b) (by proving that (a) implies (b) and that (b) implies (a)), that (b) is equivalent to (c), and that (c) is equivalent to (d). However, this way requires proving six implications, which is clearly a lot more work than just proving four implications!
I have been given some similar tasks, and have already started proving some implications. Now I wonder, how many more implications do I have to prove? Can you help me determine this?
* One line containing two integers n (1 ≤ n ≤ 20000) and m (0 ≤ m ≤ 50000): the number of statements and the number of implications that have already been proved.
* m lines with two integers s1 and s2 (1 ≤ s1, s2 ≤ n and s1 ≠ s2) each, indicating that it has been proved that statement s1 implies statement s2.
* One line with the minimum number of additional implications that need to be proved in order to prove that all statements are equivalent.
4 0
3 2
1 2
1 3
2
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
int head[N],dfn[N],low[N],belong[N],stak[N],instack[N];
int in[N],out[N];
int incnt,outcnt;
int cnt,indexx,top,ans;
struct node{
int u,v,next;
}edge[N*]; void add(int u,int v)
{
edge[cnt].v=v;
edge[cnt].next=head[u];
head[u]=cnt++;
} void Init()
{
memset(head,-,sizeof(head));
memset(dfn,,sizeof(dfn));
memset(instack,,sizeof(instack));
cnt=indexx=top=ans=;
memset(in,,sizeof(in));
memset(out,,sizeof(out));
incnt=outcnt=;
} void tarjan(int u)
{
dfn[u]=low[u]=++indexx;
stak[++top]=u;
instack[u]=;
for(int i=head[u]; i!=-; i=edge[i].next){
int v=edge[i].v;
if(!dfn[v]){
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(instack[v])
low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u]){
ans++;
while(){
int v=stak[top--];
instack[v]=;
belong[v]=ans;
if(u==v)
break;
}
}
} int main()
{
int T,n,m;
int u,v;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
Init();
while(m--){
scanf("%d%d",&u,&v);
add(u,v);
}
for(int i=; i<=n; i++){
if(!dfn[i])
tarjan(i);
}
if(ans==){
printf("0\n");
continue;
}
for(int i=; i<=n; i++){
for(int j=head[i]; j!=-; j=edge[j].next){
int v=edge[j].v;
if(belong[v]!=belong[i]){
in[belong[v]]++;
out[belong[i]]++;
}
}
}
for(int i=; i<=ans; i++){
if(!in[i])
incnt++;
if(!out[i])
outcnt++;
}
printf("%d\n",max(incnt,outcnt));
}
return ;
}
最新文章
- CSS中对图片(background)的一些设置心得总结
- wordpress-4.4.1 数据库表结构解析
- kafka常用命令
- flex+java+blazeds 多通道好文
- python入门教程链接
- [Tool] 常用开发工具注册码(持续更新)
- make_pair
- SQL 将一列多行数据合并为一行 FOR XML PATH
- redis 2.4异常
- Spring顶级项目以及Spring cloud组件
- 使用Razor来进行页面布局
- POJ - 1182 食物链 并查集经典
- 杭电ACM2019--数列有序!
- leetcode 169. Majority Element 、229. Majority Element II
- shell编程其实真的很简单(一)
- ipconfig命令查ip的时候给别人看有危险吗
- linux-安装jdk以及tomcat
- 关于ArrayList中的iterator返回的事迭代器实例问题。
- dell 远程管理卡的使用racadm
- POJ 2485