HDU2767 Proving Equivalences(加边变为强联通图)
Proving Equivalences
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10665 Accepted Submission(s): 3606
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;
typedef long long ll;
#define pii pair<int,int>
#define pil pair<int,ll>
#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define PI acos(-1.0)
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3fll;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-') f=-;char ch=getchar();}
while(ch>=''&&ch<=''){x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
}
const int maxn=;
const int maxm=;
vector<pii> vec;
int T,n,m,head[maxn],cnt;
int dfn[maxn],lown[maxn],Stack[maxn];
int InStack[maxn],Belong[maxn],Blocks,top,tot;
int ind[maxn],outd[maxn];
struct Edge{
int to,nxt;
} edge[maxm]; void Init()
{
vec.clear();
mem(head,-);mem(dfn,);
mem(ind,);mem(outd,);
Blocks=tot=top=cnt=;
} void AddEdge(int u,int v)
{
edge[cnt].to=v;
edge[cnt].nxt=head[u];
head[u]=cnt++;
} void Tarjan(int u)
{
dfn[u]=lown[u]=++tot;
InStack[u]=;
Stack[top++]=u;
for(int e=head[u];~e;e=edge[e].nxt)
{
int v=edge[e].to;
if(!dfn[v])
{
Tarjan(v);
lown[u]=min(lown[u],lown[v]);
}
else if(InStack[v]&&dfn[v]<lown[u])
lown[u]=dfn[v];
}
if(dfn[u]==lown[u])
{
int t; Blocks++;
do{
t=Stack[--top];
Belong[t]=Blocks;
InStack[t]=;
} while(t!=u);
}
}
void solve()
{
for(int i=;i<=n;++i)
if(!dfn[i]) Tarjan(i);
} int main()
{
T=read();
while(T--)
{
n=read();m=read();
Init();
for(int i=;i<=m;++i)
{
int u,v;
u=read();v=read();
vec.pb(mkp(u,v));
AddEdge(u,v);
}
solve();
if(Blocks==) {puts("");continue;} for(int i=,len=vec.size();i<len;++i)
{
int x=vec[i].fi,y=vec[i].se;
if(Belong[x]!=Belong[y])
outd[Belong[x]]=,ind[Belong[y]]=;
}
int ans,res1=,res2=;
for(int i=;i<=Blocks;++i)
{
if(!ind[i]) ++res1;
if(!outd[i]) ++res2;
}
ans=max(res1,res2); printf("%d\n",ans);
} return ;
}
HDU2767 Proving Equivalences(加边变为强联通图)的更多相关文章
- hdu2767 Proving Equivalences,有向图强联通,Kosaraju算法
点击打开链接 有向图强联通,Kosaraju算法 缩点后分别入度和出度为0的点的个数 answer = max(a, b); scc_cnt = 1; answer = 0 #include<c ...
- 【强联通图 | 强联通分量】HDU 1269 迷宫城堡 【Kosaraju或Tarjan算法】
为了训练小希的方向感,Gardon建立了一座大城堡,里面有N个房间(N<=10000)和M条通道(M<=100000),每个通道都是单向的,就是说若称某通道连通了A房间和B房间,只说明 ...
- HDU2767 Proving Equivalences
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- hdu2767 Proving Equivalences Tarjan缩点
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- hdu2767 Proving Equivalences --- 强连通
给一个图,问至少加入�多少条有向边能够使图变成强连通的. 原图是有环的,缩点建图,在该DAG图上我们能够发现,要使该图变成强连通图必须连成环 而加入�最少的边连成环,就是把图上入度为0和出度为0的点连 ...
- 判断强联通图中每条边是否只在一个环上(hdu3594)
hdu3594 Cactus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDU 4635 多校第四场 1004 强联通
我还有什么好说,还有什么好说...... 我是SBSBSBSBSBSBSBSBSBSBSBSBBSBSBSBSBSBSBSBSBS........................ 题意 思路什么的都不 ...
- POJ 2762Going from u to v or from v to u?(强联通 + 缩点 + 拓扑排序)
[题意]: 有N个房间,M条有向边,问能否毫无顾虑的随机选两个点x, y,使从①x到达y,或者,②从y到达x,一定至少有一条成立.注意是或者,不是且. [思路]: 先考虑,x->y或者y-> ...
- Proving Equivalences(加多少边使其强联通)
Proving Equivalences Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
随机推荐
- python 基础之 模块
Python 基础之模块 一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 就是一个python文件中定义好了类和方法,实现了一些功能,可以被别的python文 ...
- C++程序员学Python
目录 C++程序员学Python 第二章.变量和数据类型 1.注释语句前用#: 2.常用于大小写函数: 第三章.列表 1.列表简述 2.修改,增加,插入,删除列表元素 第四章操作列表 1.遍历 2.创 ...
- 过滤条件的时候用between和<>的区别
无论是sqlsever还是oracle都支持between函数, 2个函数的基本语法是 WHERE A BETWEEN 1 AND 2/ WHERE A >=1 AND A <=2 ,be ...
- try-with-resources优先于try-finally
参考资料:<Effective Java>.<Java核心技术 卷1>.https://www.cnblogs.com/flyingeagle/articles/1015292 ...
- window,sts安装python
1.先在python官网下载最新的python安装,安装的时候勾上所有选项 官网:https://www.python.org/downloads/ 2.在sts里安装pyDev插件,我当时直接sea ...
- 【前端知识体系-CSS相关】CSS特效实现之Transition和Transform对比
CSS效果 1.使用div绘制图形(三角形)? <!DOCTYPE html> <html lang="en"> <head> <meta ...
- php相关知识(一)
php是服务器端脚本语言.可以生成动态页面内容,可以对数据库中的数据库进行编辑. php变量以$符号开始,后面是变量名,变量名以字母或下划线开始,变量名不能包含空格,变量名区分大小写. php的数据类 ...
- FB力挺的Pytorch深度学习 书本来了
获得 fb首席科学家力挺的 pytorch教程 发布啦, 看截图 
ffmpeg应用程序项目将其核心库libav*的使用或编程抽象成FilterGraph,InputFile,OutputFile,InputStream,OutputStream,InputFilte ...
- Video的自我学习
直播原理 视频协议 HLS协议 [主要是直播方面(好用,但延时)] HTTP Live Streaming(缩写是HLS)是一个由苹果公司提出的基于HTTP的流媒体网络传输协议. 是苹果公司Quic ...