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 ...
随机推荐
- css3 svg 物体跟随路径动画教程
css3 svg 物体跟随路径动画教程https://www.jianshu.com/p/992488f3f3fc
- php查询字符串的函数
/* 查找一个字符串在另一个字符串的第一次出现,并返回其余部分(strstr别名) */ var_dump(strchr("hello world hello", "wo ...
- RTX消息提醒工具设计文档
为什么要做 项目上线后,系统依然由各业务模块负责人自己维护.而后台运行的各种业务服务结果,不能及时反馈到业务负责人.而等到客户反馈时则会太被动.为了能及时发现并解决项目问题,设计了该工具. 可利用资源 ...
- LeetCode18. 四数之和
LeetCode18. 四数之和 给定一个包含 n 个整数的数组 nums 和一个目标值 target,判断 nums 中是否存在四个元素 a,b,c 和 d ,使得 a + b + c + d 的值 ...
- 【Java】面向对象初探
前段时间经历了一段心态浮躁期,这让我想起了自己最初的计划,要提升自己知识体系的广度.前几年一直做的是web前端这一块的工作,但我希望通过自己在学习Java这样的过程来提升自己的知识广度. 面向对象概述 ...
- 成员函数指针,动态绑定(vc平台)
上一篇介绍了gcc对成员函数指针做了thunk的处理,本篇介绍vc对成员函数指针如何处理,还有动态绑定相关的处理. 同样用回上一篇的例子: struct point {float x,y;}; str ...
- Java开发中常用jar包整理及使用
本文整理了我自己在Java开发中常用的jar包以及常用的API记录. <!-- https://mvnrepository.com/artifact/org.apache.commons/com ...
- python基础-面向对象编程之封装、访问限制机制和property
面向对象编程之封装 封装 定义:将属性和方法一股脑的封装到对象中,使对象可通过"对象."的方式获取或存储数据. 作用:让对象有了"."的机制,存取数据更加方便 ...
- cognos服务器性能测试诊断分析优化过程记录
前段时间客户方一个系统上线后出现性能问题,就是查询报表的时候出现宕机现象,应项目组要求过去帮忙测试优化问题. 该项目的架构相对比较复杂,登录后要先进行认证服务器认证用户然后登录到应用系统A,在跳转到 ...
- LoadRunner中的90%响应时间
LoadRunner中的90%响应时间是什么意思?这个值在进行性能分析时有什么作用? 为什么要有90%用户响应时间? 这个跟超女.舞林大会等比赛那样在比赛后都要去掉一个最高分一个最低分在取平均值有点类 ...