hdoj2767 Proving Equivalences(强连通分量+缩点)

相机标定原理与张氏标定法 这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 欢迎使用Markdown编辑器 你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Mar 阅读详情

Proving Equivalences

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3093    Accepted Submission(s): 1162


Problem Description
Consider the following exercise, found in a generic linear algebra textbook.

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?
 

Input
On the first line one positive number: the number of testcases, at most 100. After that per testcase:

* 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.
 

Output
Per testcase:

* One line with the minimum number of additional implications that need to be proved in order to prove that all statements are equivalent.
 

Sample Input
  
2 4 0 3 2 1 2 1 3
 

Sample Output
  
4 2
 

Source
 

Recommend
lcy   |   We have carefully selected several similar problems for you:   2768  2766  2769  2773  2772 
 


将每个联通分量当成一个点,之后成了一个DAG(有向无环图) 


s1=入度为0的点,s2=出度为0的点,然后取s1,s2的最大值就行



#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include<stack>
using namespace std;
const int N=20010;
int b[N*3],dfn[N],lowlink[N],num[N];
int in[N],out[N];
bool instack[N];
vector<int> g[N];
stack<int> s;
int sign;
int ans;
int n,m;
void init()
{
    for(int i=0;i<N;i++)
        g[i].clear();
    memset(dfn,0,sizeof(dfn));
    memset(lowlink,0,sizeof(lowlink));
    memset(b,0,sizeof(b));
    memset(num,0,sizeof(num));
    memset(instack,0,sizeof(instack));
}
void add_edge(int a,int b)
{
    g[a].push_back(b);
    return;
}


void tarjan(int u)
{
    //cout<<"in"<<endl;
    dfn[u]=lowlink[u]=sign;
    sign++;
    s.push(u);
    instack[u]=true;
    for(int i=0;i<g[u].size();i++)
    {
        int x=g[u][i];
        if(!dfn[x])
        {
            tarjan(x);
            lowlink[u]=min(lowlink[u],lowlink[x]);
        }
        else if(instack[x])
            lowlink[u]=min(lowlink[u],dfn[x]);
    }
    if(dfn[u]==lowlink[u])
    {
        //cout<<"no"<<endl;
        int t=-1;
        ans++;
        while(t!=u)
        {
             t=s.top();s.pop();
            instack[t]=false;
            num[t]=ans;
        }
    }
    //cout<<"yes"<<endl;
}
int solve()
{
    if(ans==1)
        return 0;
       // cout<<num[1]<<num[2]<<num[3]<<endl;
    memset(in,0,sizeof(in));
    memset(out,0,sizeof(out));
    //cout<<"n="<<n<<endl;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<g[i].size();j++)
        {
            int x=g[i][j];
            if(num[i]!=num[x])
            {
                //cout<<i<<" "<<x<<endl;
                out[num[i]]++;
                in[num[x]]++;
            }
        }
    }
    int s1=0,s2=0;
  //cout<<"ans="<<ans<<endl;
  //cout<<in[1]<<in[2]<<in[3]<<endl;
    for(int i=1;i<=ans;i++)
    {
        if(in[i]==0) s1++;
        if(out[i]==0) s2++;
    }
    return max(s1,s2);
}
int main()
{
    int ca;
    scanf("%d",&ca);
    while(ca--)
    {
        scanf("%d%d",&n,&m);
        init();
        for(int i=0;i<m;i++)
        {
            int aa,bb;
            scanf("%d%d",&aa,&bb);
            add_edge(aa,bb);
        }
        //cout<<"yes"<<endl;
        sign=1;ans=0;
        for(int i=1;i<=n;i++)
        {
            //cout<<"no"<<endl;
            if(!dfn[i])
                tarjan(i);
        }
        //cout<<"ans="<<ans<<endl;
        printf("%d\n",solve());
    }
    return 0;
}



































【华为OD机试真题 2025C卷】895、贪心歌手 | 机试真题+思路参考+代码解析 (C++、Java、Py、C语言、JS) 【华为OD机试真题 2025C卷】895、贪心歌手 | 机试真题+思路参考+代码解析 (C++、Java、Py、C语言、JS) 华为od机试,华为od机试真题,华为od机试E卷,华为odE卷,华为od机试真题E卷,华为OD,华为OD机试,华为OD机试真题,华为od机考,华为od机试D卷,华为od机试真题D卷,华为od手撕代码,华为od,华为od机试C卷,华为od e卷,华为2025e卷,od机试,2025E卷,华为OD机试E卷,什么是华为od,华为od介绍,全面了解华为od,2025华为od,如何备战华 阅读详情

相关推荐

二叉树随机漫步

元旦快乐! 学习到中本聪bitcoin的文章的calculation部分的时候,出现了binomial random walk,不是很明白什么是random walk。发现这个文章写的很好:https://blog.youkuaiyun.com/fireguard/article/details/16111603 随机漫步,也叫随机游走,最早是物理学中做"布朗运动"的微观粒子的运动形态来形成的一个模型,布朗运...

gjq5464的博客 1737

HDU1269(强连通分量)

强连通图:在有向图中,任意节点除法都可以到达其余所有节点,则称为强连通图。 强连通分量:在非强连通图的有向图中,选取部分点为强连通图,该强连通子图称为强连通分量 #include<iostream> #include<algorithm> #include<cmath> #include<cstring> #include<cstdio> #include<vector> #include<stack> using name

Keep_Trying_Go的博客 454

containerd镜像加速配置全解析:从host.toml到config.toml的演进与实践

本文全面解析了containerd镜像加速的配置方法,重点对比了传统的config.toml集中式配置与现代的host.toml模块化配置的演进与优劣。文章通过实战演示,详细指导如何为docker.io、registry.k8s.io等常见仓库配置host.toml加速,并提供了生产环境下的最佳实践、故障排查与性能优化建议,帮助用户显著提升镜像拉取效率与系统稳定性。

jenkins8butler的博客 698

HDU 2767( Proving Equivalences )强连通模板(tarjan 模板)简易

该文主要是写一下强连通题目的一种方法tarjan的模板,这是一种判断连通分支的一种方法,能够准确的找出图的强连通分支,并且,将其编号。 下面的是一个HDU中的一个模板题: Proving Equivalences Consider the following exercise, found in a generic linear algebra textbook. Let A be...

weixin_40488730的博客 238

【自动驾驶端到端5:VADv2: End-to-End Vectorized Autonomous Driving via Probabilistic Planning】

从大规模人类驾驶演示中学习类人驾驶策略是有希望的。但是,规划的不确定性使得从驾驶演示中提取驾驶知识是有挑战性的。从统计学习的角度来看,动作(包括实际和速度)是高度随机的,受许多无法建模的潜在因素影响。

weixin_40000560的博客 1405

CTFshow MISC入门实战:010Editor+TweakPNG解决PNG隐写难题(附完整脚本)

本文详细介绍了在CTFshow MISC比赛中,如何利用010Editor和TweakPNG两款专业工具构建高效的PNG隐写分析工作流。文章从PNG文件结构解析入手,通过实战案例演示了如何协同使用010Editor进行二进制侦察与结构分析,以及使用TweakPNG进行数据块的精准编辑与删除,并最终提供了自动化分析脚本,帮助选手系统性地解决PNG隐写难题。

weixin_29252171的博客 75

HDU2767-强连通

Proving Equivalences Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9532 Accepted Submission(s): 3362 Problem Description Consider the foll...

z1164754004z的博客 219

OpenClaw实战系列03:Slack/Telegram国际版接入实战指南

在当今的软件开发和工作流自动化中,将项目管理工具与即时通讯平台集成已成为提高团队协作效率的关键。OpenClaw作为一个开源的自动化工具,通过接入Slack和Telegram国际版,可以实现实时通知、自动化任务触发和团队协作的无缝对接。本文将详细介绍如何实现OpenClaw与这两个主流即时通讯平台的集成。OpenClaw是一个开源的自动化工作流引擎,支持多种触发器和执行器,能够帮助开发团队实现CI/CD流程、任务调度、监控告警等自动化场景。模块化设计:支持插件化扩展多触发器支持。

PeterPan的博客 587

hdu2767(图的强连通)

//题意:问需要添加几条边使得这张图成为每个点都等价(强连通图) 我们先把图中的强连通分量缩点 可能他本身就是满足条件,那么直接输出0 经过缩点后,就可以把强连通分量看成一个个独立的点,在这张图上搞一个强连通图,我们可以根据强连通的性质,也就是每个点都要有被指向边和出去的边,那么也就是求一下每个点(强连通分量)的入度和出度,把出度==0的点个数加起来,把入度==0的点个数...

weixin_30915951的博客 194

DTI-ALPS 指标计算(附代码),评估脑类淋巴系统功能

DTI-ALPS 指标计算(附代码),评估脑类淋巴系统功能

xxx 1051

08-StarRocks性能调优FAQ

StarRocks性能调优摘要 本文提供了StarRocks数据库性能调优的常见问题解答,涵盖查询优化、索引设计、分区策略和系统配置等关键方面。主要内容包括:查询优化技巧(使用EXPLAIN分析、避免全表扫描、优化JOIN和聚合查询);索引选择与维护建议(高频查询列索引、复合索引);分区策略设计(时间分区、范围分区)及其管理方法;以及系统内存配置优化(JVM参数调整、查询内存限制设置)。这些优化措施可显著提升StarRocks的查询性能和系统效率。

欢迎来到我的博客,一起探索代码里的世界! 541

hdu2767(强连通分量+缩点)

Proving EquivalencesTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7367 Accepted Submission(s): 2547Problem Description Consider the follo

gh6267的博客 499

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

HDOJ 2767 Proving Equivalences

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2767 题意:给你一个些点的关系,然后问你还需要加多少条边可以使这个图变成强连通,也就是每个点都可以通过其他的点到达另外的点。 如果这个图它不含环的话,很容易想到统计每个点的入度和出度,然后其中最大的那个就是我们要加的边的条数,但是实际情况肯定不可能是这样的,难免会遇到含环的情况。这里我们就可以考虑

RaAlGhul的博客 634

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

LA-4287 & HDOJ-2767 Proving Equivalences 解题报告

强连通分量题。

JZQT_T的博客 1049

HDU 2767 Proving Equivalences(强连通分量)

HDU 2767 Proving Equivalences(强连通分量) http://acm.hdu.edu.cn/showproblem.php?pid=2767 题意:给你一个有向图,问你在图中最少要加多少条边能使得该图变成一个强连通图. 分析:        首先我们求出该图的各个强连通分量,然后把每个强连通分量看出一个点(即缩点),然后我们得到了一个有向无环图(DAG).

code 1566

hdoj 2767 Proving Equivalences 【有向图 增加最少的边使图强连通】

Proving Equivalences Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3897    Accepted Submission(s): 1409 Problem Description Con

世界很大 1152

HDOJ--2767--Proving Equivalences

Proving Equivalences Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3897    Accepted Submission(s): 1409 Problem Description C

粥同学的学习笔记 711

hdoj Proving Equivalences 2767 (强连通分量 最少添加几条边使图强连通)

Proving Equivalences Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4329    Accepted Submission(s): 1537 Problem Description Consider

yanghui07216的博客 949

HDOJ 2767 Proving Equivalences(强连通算法入门)

题意: 一个有向图,问至少添加几条边让整个图变成强连通图。 思路: 1. 基本上是模板题,首先对有向图进行缩点,即把所有强连通分量看成是一个点,Targan 算法http://www.byvoid.com/blog/scc-tarjan/ 2. 统计出度和入度为 0 的点的个数,输出其中的最大的一个即可。 #include <iostream> #incl...

weixin_30788239的博客 152

hdoj--2767--Proving Equivalences (scc+缩点)

Proving Equivalences Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 1   Accepted Submission(s) : 1 Problem Description Consider the followi

playboy307 314

hdoj Equivalent Sets 3836 (强连通分量 最少添加几条边使图强连通)

Equivalent Sets Time Limit: 12000/4000 MS (Java/Others)    Memory Limit: 104857/104857 K (Java/Others) Total Submission(s): 3597    Accepted Submission(s): 1252 Problem Description To prove tw

yanghui07216的博客 536

Hdu--2767(强连通分量,缩点)

2014-10-1402:19:23思路:大白书的例题,挺好的强连通分量入门题。问题的大意就是问最少添加几条边能使一个有向图强连通。做法是,先求一遍强连通分量,然后把每个强连通分量缩点,这样实际上就形成了DAG,接下来只要判断每个缩点的入度和出度,找出入度为0的点个数a1,出度为0的点个数a2,然后取a1和a2的最大值,即是答案。(因为最终要使得每个缩点的入度、出度不为零,而添加一条边...

dingdi3021的博客 182

HDU 2767 强联通分量

点击打开链接 题意:问加多少边后图会变成强联通分量为1的图 思路:简单的强联通,缩点后找入度和出度就行了,水题#include #include #include #include #include #include using namespace std; typedef long long ll; const int inf=0x3f3f3f3f; const int maxn

Dan__ge的博客 4693

HDU 2767

题意:给你一个有向图,问需要增加多少条边成文一个强联通图。。。。 题解:求每个强联通分支度(出度入度)为零和的最大值。。。 #include #include #include #include #include #include #include #include //#include #include #include using namespace std; #define

不吸血的Vampire 612

HDU2767 强连通 Tarjan缩点

hdu2767 题意:求最少要添加几条边使得已知的图变成强连通图题意:求最少要添加几条边使得已知的图变成强连通图题意:求最少要添加几条边使得已知的图变成强连通图 题解:Tarjan,缩点,那么只需要在缩成的点之间建边就行了。题解:Tarjan,缩点,那么只需要在缩成的点之间建边就行了。题解:Tarjan,缩点,那么只需要在缩成的点之间建边就行了。 缩完点后若某个强连通分量的出度或者入度为0,那么就...

WayJasy的博客 252

hdu2767——tarjan强连通分量

hdu2767 题意 给n个点和m条有向边,求最少还需多少条边n个点构成强联通图。 思路 tarjan先处理出每一个强连通分量。 如果强连通分量的个数为1,则答案为0。 如果强连通分量的个数大于1,将每个强连通分量看成一个点,每个强连通分量之间可能存在边,a为没有出度的强连通分量的个数,b为没有入度的强连通分量的个数。则答案为max(a,b)(动手画下很容易得到)。 #include <bi...

D_Bamboo_的博客 298
上一篇: hdoj1532Drainage Ditches(网络流)
下一篇: poj3114Countries in War(强连通分量加缩点)
IT旅行
博客等级 码龄12年 3粉丝 28原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值