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 基础之 I/O 模型
一.I/O模型 IO在计算机中指Input/Output,也就是输入和输出.由于程序和运行时数据是在内存中驻留,由CPU这个超快的计算核心来执行,涉及到数据交换的地方,通常是磁盘.网络等,就需要IO接 ...
- CentOS7 编码编译安装或卸载http2.4.25 一键脚本
待完善 CentOS 7测试 哈哈 #!/bin/bash #************************************************************** #Autho ...
- ASP.NET Core 1.0: 指定Static File中的文件作为default page
指定一个网站的default page是很容易的事情.譬如IIS Management中,可以通过default page来指定,而默认的index.html, index.htm之类,则早已经被设置 ...
- nyoj 4 ASCII码排序
ASCII码排序 时间限制:3000 ms | 内存限制:65535 KB | 难度:2 描述 输入三个字符(可以重复)后,按各字符的ASCII码从小到大的顺序输出这三个字符. 输入 第一 ...
- 【PostMan】批量参数化的用法 之 text/csv
目的:批量参数化,单个循环多次使用不同的参数请求. 测试数据准备 新建txt文件,输入格式: 首行 --->参数名 其他行 --->测试数据(不同测试数据需要换行) 如下所示,Number ...
- windows 10安装和配置caffe教程 | Install and Configure Caffe on windows 10
本文首发于个人博客https://kezunlin.me/post/1739694c/,欢迎阅读! Install and Configure Caffe on windows 10 Part 1: ...
- 2011-11-14:命令执行漏洞防御,PHP反序列化漏洞产生原因,笔记
命令执行漏洞防御尽量不要使用系统执行命令在进入执行命令函数方法之前,变量一定要做好过滤,对敏感字符进行转义在使用动态函数之前,确保使用的函数是指定的函数之一对PHP语言来说,不能完全控制的危险函数最好 ...
- 2019-10-9:渗透测试,基础学习the-backdoor-factory-master(后门工厂)初接触
该文章仅供学习,利用方法来自网络文章,仅供参考 the-backdoor-factory-master(后门工制造厂)原理:可执行二进制文件中有大量的00,这些00是不包含数据的,将这些数据替换成pa ...
- 新闻实时分析系统-MySQL安装
1.修改yum源 鉴于用国外的Yum源,速度比较慢,所以想到将国外的yum源改为国内的Yum源,这里选择使用比较多的阿里云源.具体修改方法可以参考此连接 2.在线安装mysql 通过yum在线mysq ...
- Fortran流程控制与逻辑运算、循环--xdd
1.IF语句 1 if() then ... end if 2 if() then ... else ... end if 3 if() then ... else if() then ... els ...