【HDOJ2767】【Tarjan缩点】
http://acm.hdu.edu.cn/showproblem.php?pid=2767
Proving Equivalences
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8605 Accepted Submission(s): 3063
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?
* 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
//Wannafly挑战赛14 C https://www.nowcoder.com/acm/contest/81/C
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
const int maxn=;
struct edge{
int from;
int to;
int next;
}EDGE[maxn];
vector<int>vc[maxn];
int head[maxn],dfn[maxn],vis[maxn],low[maxn],col[maxn],in[maxn],out[maxn],en[maxn],stk[maxn];//各个变量的意义可参照上篇博客
int edge_cnt=,tot1=,tot2=,scc_cnt=,tot0=;
void add(int x,int y)
{
EDGE[edge_cnt].from=x;
EDGE[edge_cnt].to=y;
EDGE[edge_cnt].next=head[x];
head[x]=edge_cnt++;
}
void Tarjan(int u)
{
low[u]=dfn[u]=++tot1;//注意tot1的初值必须是1【因为dfn必须为正数】,所以这里使用++tot1而不用tot1++;
vis[u]=;
stk[++tot2]=u;
for(int i = head[u]; i != - ; i = EDGE[i].next)
{
if(!dfn[EDGE[i].to]){
Tarjan(EDGE[i].to);
low[u]=min(low[u],low[EDGE[i].to]);
}
else if(vis[EDGE[i].to]){
low[u]=min(low[u],low[EDGE[i].to]);
}
}
if(low[u]==dfn[u]){
int xx;
scc_cnt++;
do{
xx=stk[tot2--];
vc[scc_cnt].push_back(xx);
col[xx]=scc_cnt;
vis[xx]=;
}while(xx!=u);
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
edge_cnt=,tot1=,tot2=,scc_cnt=,tot0=;
scc_cnt=;
int n,m;
scanf("%d%d",&n,&m);
memset(head,-,sizeof(head));
memset(stk,,sizeof(stk));
memset(in,,sizeof(in));
memset(out,,sizeof(out));
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
memset(col,,sizeof(col));
while(m--)
{
int a,b;
scanf("%d%d",&a,&b);
add(a,b);
}
for(int i = ; i <= n; i++)
{
if(!dfn[i])Tarjan(i);
}
for(int i = ; i < edge_cnt ; i++)
{
if(col[EDGE[i].from]!=col[EDGE[i].to])
{
in[col[EDGE[i].to]]++;//缩点
out[col[EDGE[i].from]]++;
}
}
int sum1=,sum2=;
for(int i = ; i <= scc_cnt ; i++)
{
if(!in[i])
sum1++;
if(!out[i])
sum2++;
}
int mmax=max(sum1,sum2);
if(scc_cnt!=)
cout << mmax << endl;
else
cout << "" <<endl;
for(int i = ; i <= scc_cnt ; i++)
vc[i].clear();
}
return ;
}
/*4 5
1 3
2 4
4 2
1 4
2 1*/
【HDOJ2767】【Tarjan缩点】的更多相关文章
- hihoCoder 1185 连通性·三(Tarjan缩点+暴力DFS)
#1185 : 连通性·三 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 暑假到了!!小Hi和小Ho为了体验生活,来到了住在大草原的约翰家.今天一大早,约翰因为有事要出 ...
- POJ 1236 Network of Schools(Tarjan缩点)
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16806 Accepted: 66 ...
- King's Quest —— POJ1904(ZOJ2470)Tarjan缩点
King's Quest Time Limit: 15000MS Memory Limit: 65536K Case Time Limit: 2000MS Description Once upon ...
- 【BZOJ-2438】杀人游戏 Tarjan + 缩点 + 概率
2438: [中山市选2011]杀人游戏 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1638 Solved: 433[Submit][Statu ...
- 【BZOJ-1924】所驼门王的宝藏 Tarjan缩点(+拓扑排序) + 拓扑图DP
1924: [Sdoi2010]所驼门王的宝藏 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 787 Solved: 318[Submit][Stat ...
- 【BZOJ-1797】Mincut 最小割 最大流 + Tarjan + 缩点
1797: [Ahoi2009]Mincut 最小割 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1685 Solved: 724[Submit] ...
- BZOJ 1051 受欢迎的牛(Tarjan缩点)
1051: [HAOI2006]受欢迎的牛 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 4573 Solved: 2428 [Submit][S ...
- HDU4612+Tarjan缩点+BFS求树的直径
tarjan+缩点+树的直径题意:给出n个点和m条边的图,存在重边,问加一条边以后,剩下的桥的数量最少为多少.先tarjan缩点,再在这棵树上求直径.加的边即是连接这条直径的两端. /* tarjan ...
- POJ 1236 Network of Schools(强连通 Tarjan+缩点)
POJ 1236 Network of Schools(强连通 Tarjan+缩点) ACM 题目地址:POJ 1236 题意: 给定一张有向图,问最少选择几个点能遍历全图,以及最少加入�几条边使得 ...
随机推荐
- 【Jmeter基础知识】Jmeter响应断言和断言结果
一.Jmeter创建一个响应断言 1.步骤:添加--断言--响应断,进入响应断言页面 2.断言内容:可以采用直接去搜索某些文本信息,或者可以去断言某个变量,如图 二.Jmeter创建一个断言结果 1. ...
- mybatis输出sql语句
方法一: 这种方法是mybatis官网上介绍的,比较好用: log4j.properties: log4j.rootLogger=ERROR,consolelog4j.appender.console ...
- linux150条命令
●线上查询及帮助命令(2 个)man help ●文件和目录操作命令(13 个) ls tree pwd mkdir rmdir cd touch cp mv rm ln find rename ●查 ...
- Saiku部分函数解析(八)
Saiku函数解析 1. now() : 获取当前日期 直接使用即可 2. IIF(logic_exp, string, string): IIF判断,logic_exp是逻辑表达式,结果为t ...
- js onclick函数中传字符串参数的问题
规则: 外变是“”,里面就是‘’外边是‘’,里边就是“” 示例: var a="111"; var html="<a onclick='selecthoods( ...
- js批量上传文件
html代码: <input type="file" id='upload' name="upload" multiple="multiple& ...
- flask小例
#写一个app.py,处理3个URL: ''' GET / : 首页,返回Home; GET /signin:登录页,显示登录表单; POST /signin: 处理登录表单,显示登录结果. ''' ...
- (C/C++学习笔记) 二十二. 标准模板库
二十二. 标准模板库 ● STL基本介绍 标准模板库(STL, standard template library): C++提供的大量的函数模板(通用算法)和类模板. ※ 为什么我们一般不需要自己写 ...
- 2.15 C++常量指针this
参考: http://www.weixueyuan.net/view/6346.html 总结: 在每一个成员函数中都包含一个常量指针,我们称其为this指针,该指针指向调用本函数的对象,其值为该对象 ...
- DevExpress ASP.NET v18.2新功能详解(三)
行业领先的.NET界面控件2018年第二次重大更新——DevExpress v18.2日前正式发布,本站将以连载的形式为大家介绍新版本新功能.本文将介绍了DevExpress ASP.NET Cont ...