HDU 2767 Proving Equivalences——————Kosaraju求强连通分量

【图论】Kosaraju算法详解 讲 Kosaraju 算法之前要先知道什么是强连通分量(SCC) 强连通分量 对于一个有向图顶点的子集 S ,如果在 S 内取两个顶点 u 和 v ,都能找到一条从 u 到 v 的路径,那么就称 S 是强连通的。 如果在强连通的顶点集合 S 中加入其他任意顶点集合后,它都不再是强连通的,那么就称 S 是原图的一个强连通分量(SCC:strongly connected componen... 阅读详情

Proving Equivalences

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 ©, that © 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 ©, and that © 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


给你一个图,问你至少要加多少条边可以使这个图变成强连通的
Koasraju求出DAG后
num1 = DAG中入度为0点的个数
num2 = DAG中出度为0点的个数

ans =max(num1, num2)

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+7;
int cmp[MAXN], ind[MAXN], outd[MAXN], V;
bool used[MAXN];
vector<int> G[MAXN];
vector<int> rG[MAXN];
vector<int> vs;

void add_edge(int x,int y)
{
        G[x].push_back(y);
        rG[y].push_back(x);
}


void dfs(int v)
{
        used[v] = true;
        for(int i=0;i<(int)G[v].size();++i)
                if(!used[G[v][i]])      dfs(G[v][i]);
        vs.push_back(v);
}

void rdfs(int v, int k)
{
        used[v] = true;
        cmp[v]  = k;
        for(int i=0;i<(int)rG[v].size();++i)
                if(!used[rG[v][i]])     rdfs(rG[v][i], k);
}

int scc()
{
        memset(used, 0, sizeof(used));
        vs.clear();
        for(int v=0;v<V;++v)
                if(!used[v])    dfs(v);
        memset(used, 0, sizeof(used));
        int k = 0;
        for(int i = vs.size() - 1; i >= 0; --i)
                if(!used[vs[i]])        rdfs(vs[i], k++);
        return k;
}

int main()
{
        // freopen("../in.txt","r",stdin);
        // freopen("../out.txt","w",stdout);
        int T, n, m;
        cin>>T;
        while(T--)
        {
                cin>>n>>m;
                V = n;
                for(int i=0;i<=n;++i)
                {
                        G[i].clear();
                        rG[i].clear();
                }
                for(int i = 0; i < m; ++i)
                {
                        int x, y;
                        cin>>x>>y;
                        add_edge(x-1,y-1);
                }
                int N = scc();
                if(N==1)
                {
                        cout<<0<<endl;
                        continue;
                }
                memset(ind, 0, sizeof(ind));
                memset(outd,0,sizeof(outd));
                for(int v = 0; v < V; ++v)
                        for(int i = 0;i < (int)G[v].size(); ++i)
                                if(cmp[v]!=cmp[G[v][i]])
                                {
                                        ind[cmp[G[v][i]]]++;
                                        outd[cmp[v]]++;
                                }
                int num1 = 0;
                int num2 = 0;
                for(int i = 0; i < N; ++i)
                {
                        if(!ind[i])      num1++;
                        if(!outd[i])     num2++;
                }
                cout<<max(num1, num2)<<endl;
        }
        return 0;
}

从0到1:OpenClaw 助力单元测试代码自动化与覆盖率飞升 OpenClaw 的横空出世,宛如一道曙光,照亮了这片黑暗的领域。它作为一款强大的本地 AI 助手,拥有着令人惊叹的能力。OpenClaw 能够深入理解代码的逻辑结构,自动分析代码中的各种功能和潜在的风险点,从而精准地生成高质量的单元测试代码。它就像是一位不知疲倦的测试专家,能够快速、准确地完成那些繁琐的测试编写工作,将开发者从重复劳动中解放出来,让他们能够将更多的精力投入到更具创造性和价值的工作中。 阅读详情

相关推荐

从零到一:用Verilog和Quartus构建智能交通灯系统的实战指南

本文详细介绍了如何使用Verilog和Quartus Prime从零开始构建智能交通灯系统。通过分步指导,包括状态机设计、时序控制、数码管显示等核心模块实现,并结合ModelSim仿真验证,帮助FPGA初学者掌握数字电路设计的关键技术。文章还提供了实际部署到FPGA开发板的调试技巧和进阶优化方案。

weixin_29172201的博客 476

HDU - 2767 Proving Equivalences【Tarjan】

Time limit 2000 ms Memory limit 32768 kB 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: A i...

niiick 256

从Protocol到硬件控制:揭秘高通UEFI中ABL与XBL的协作机制

本文深入解析了高通UEFI架构中ABL与XBL的协作机制,重点探讨了Protocol通信在硬件控制中的关键作用。通过对比传统GPIO控制方式,揭示了Protocol架构在安全性、可维护性和灵活性方面的优势,并提供了关机充电场景的实战案例分析及调试技巧。

weixin_29185199的博客 431

22无限循环注册_C语言循环结构习题及答案

点击蓝字关注我们FOLLOW US1.下列程序段执行后s的值为(D )。 int i=5, s=0; while(i--) if (i%2) continue; else s+=i;A.15B.10C.9D.62.下列程序段执行后s值为_D_。int i=5, s=0;while(i--) if (i%2) continue; el...

weixin_32139875的博客 1万+

【SpringBoot 3.x 第43节】你还敢说 Spring 启动慢是“宿命”?Spring AOT 把启动剧本都提前写死了,你服不服?

🏆本文收录于《滚雪球学SpringBoot 3》,专门攻坚指数提升,本年度国内最系统+最专业+最详细(永久更新)。

**My Coding Family** 540

英伟达 Jetson AGX Thor 官方入门教程(一)系统U盘安装

NVIDIA Jetson AGX Thor开发套件快速安装指南 本指南详细介绍了NVIDIA Jetson AGX Thor开发套件的安装流程。该套件搭载T5000 SoM,为物理AI和机器人应用提供强大支持。安装过程采用全新的JetPack 7.0方案,通过USB闪存盘即可完成BSP(Jetson Linux)安装,无需依赖Ubuntu主机。指南包含硬件开箱说明、两种配置模式(带显示器/无显示器)、详细的ISO镜像下载和USB制作步骤(推荐使用Balena Etcher工具),以及首次启动后的初始设置流

机器人控制与仿真应用 2868

北航软院2012级C#期末考试部分考题解答

博主注:本渣渣水平有限,文中若有不对的地方敬请指出,谢谢。 本文中大部分图片来自老师的PPT,感谢邵老师,想要的可以点击右边QQ联系我:) 一、选择题(2*15=30) 1.In C# what is base class of all reference types? System.Type B. System.Base C.System.Object D.Syst...

weixin_30852367的博客 1095

车载以太网:PHY(物理层)介绍

本文以TJA1101芯片为实例介绍了车载以太网PHY(物理层)组成。

kevin1499的博客 6231

tarjan模板(强联通分量)

void tarjan(int i) { int j; DFN[i]=LOW[i]=++Dindex; instack[i]=true; Stap[++Stop]=i; for (edge *e=V[i];e;e=e->next) { j=e->t; if (!DFN[j]) {

IWBE的专栏 801

2024年上半年试题二:论性能测试方法及其应用

2025年1月,我以系统分析师的身份参与了公司OA系统的开发与建设。该系统包含的功能有打卡签到、公文流转、工资查询等。我们吸取了之前由于系统使用人数激增暴露出的短时间卡顿等问题,所以在本次开发中,我们非常重视系统的性能测试。通过自动化的测试工具模拟多种正常、峰值及异常负载条件对系统的各项性能指标进行测试。性能测试在软件的质量保证中起着重要的作用,它包括的测试内容丰富多样,常见的负载测试和压力测试都属于性能测试。

银帅 548

STM32F103(二十三)通用同步异步收发器(USART)

学习板:STM32F103ZET6 往期博客: STM32F103五分钟入门系列(一)跑马灯(库函数+寄存器)+加编程模板+GPIO总结 STM32F103五分钟入门系列(二)GPIO的七大寄存器+GPIOx_LCKR作用和配置 STM32F103五分钟入门系列(三)GPIO的常用库函数使用方法总结+一个网络上的误区 STM32F103五分钟入门系列(四)蜂鸣器实验(库函数+寄存器) STM32F103五分钟入门系列(五)按键实验(库函数+寄存器) STM32F103五分钟入门系列(六)时钟框图+相关寄存器

Curnane0_0的博客 1019

HDU 5934 Bomb 【强连通缩点】

Problem Description There are N bombs needing exploding. Each bomb has three attributes: exploding radius ri, position (xi,yi) and lighting-cost ci which means you need to pay ci cost ma

Head_Hard的博客 317

【微服务】SpringBoot 4.0 新特性整合项目实战应用详解

SpringBoot 4.0 新特性整合项目实战应用详解

congge 4588

hdu2767 Proving Equivalences,有向图强联通,Kosaraju算法

点击打开链接 有向图强联通,Kosaraju算法 缩点后分别入度和出度为0的点的个数 answer = max(a, b); scc_cnt = 1; answer = 0 #include #include #include #include #include using namespace std; const int maxn = 20000 + 1

天亮说晚安 1733

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Proving Equivalences(HDU 2767)------加边成强连通分量

题目链接 题目描述 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: A is invertible. Ax = b has exa...

weixin_43960284的博客 250

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Hdu 2767 Proving Equivalences【强联通-Kosaraju+思维】

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

mengxiang000000 449

HDU 5934 Bomb(强连通分量)

Problem Description There are N bombs needing exploding.Each bomb has three attributes: exploding radius ri, position (xi,yi) and lighting-cost ci which means you need to pay ci cost making it explode

henuzxy 344

HDU-5934 Bomb(tarjan缩点+入度0最小和)

                                      BombThere are NN bombs needing exploding. Each bomb has three attributes: exploding radius riri, position (xi,yi)(xi,yi) and lighting-cost cici which means you ne...

MengX 376

HDU6165(tarjan算法 强连通缩点,拓扑排序)

这里说明一下,tarjan是一个人,他发明的算法都以他命名,所以,tarjan后面要加后缀,不然不知道是哪个算法。 一道比较标准的模板题,这里有篇很好的讲强 tarjan求连通分量 的博客点击打开链接 我这里直接把新图构建出来了,然后拓扑排序即可,只要那一层出现两个入度为0的点即不能到达。 #include #include #include #include #include #inclu

UFO___的博客 802

HDU 5934 强连通分量

There are NN bombs needing exploding. Each bomb has three attributes: exploding radius riri, position (xi,yi)(xi,yi) and lighting-cost cici which means you need to pay cici cost making it explode. If a un-lighting bomb is in or on the border the explod

雪的期许 1022

Bomb(HDU-3555)

Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the curre...

Alex_McAvoy的博客 438

牛客-沙漠点列【tarjan】

正题 题目链接:https://ac.nowcoder.com/acm/contest/1101#question 题目大意 nnn个点mmm条边的沙漠(所有联通子图都是仙人掌),删除kkk个点使得剩下的连通块最多。 解题思路 对于图上的每条割边,删去之后就可以多出一个联通块,所以我们就可以先删去所有割边。 之后图上剩下许多个环,没两个环之间由一个割点连接,所以我们可以用缩点双联通分量的方法找...

QuantAsk 424

2016中国大学生程序设计竞赛(ccpc 杭州)题解报告

2016中国大学生程序设计竞赛(ccpc 杭州)题解报告

queuelovestack的专栏 5907
上一篇: HDU 1827 Summer Holiday——————(Kosaraju求强连通分量,缩点)
下一篇: HDU 3836Equivalent Sets——————Kosaraju求强连通分量
陶鸿杰
博客等级 码龄9年 93粉丝 298原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值