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;
}

从Zemax到Speos:HUD设计数据无缝迁移避坑指南(含STEP文件精度验证) 本文详细介绍了从Zemax到Speos的HUD设计数据无缝迁移方法,重点解决Zernike曲面参数保真、虚拟厚度设置和坐标系对齐等核心问题。通过STEP文件精度验证和工程化解决方案,帮助工程师避免数据迁移中的常见陷阱,提升HUD系统设计效率。适用于Ansys Zemax和Ansys Speos用户,优化光学性能验证流程。 阅读详情

相关推荐

MounRiver Studio实战:像管理个人项目一样整理沁恒MCU的EVT例程(附文件结构图)

本文详细介绍了如何使用MounRiver Studio重构沁恒MCU的EVT例程,实现工程化管理。通过分析官方EVT设计的局限性,提出标准化的目录结构和迁移步骤,帮助开发者提升代码可维护性和团队协作效率。文章还提供了MounRiver Studio的关键配置参数和常见问题排查指南,适用于沁恒MCU开发者。

weixin_33940469的博客 356

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

MATLAB新手必看:5分钟搞定直流无刷电机Simulink仿真(附完整模型下载)

本文为MATLAB新手提供直流无刷电机Simulink仿真的快速入门指南,涵盖从环境配置到速度控制闭环实现的完整流程。通过详细的模块选择和参数设置说明,帮助读者5分钟内搭建基础仿真模型,并附赠完整模型下载,助力快速掌握电机控制仿真技术。

efc123456的博客 984

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万+

无源低通滤波器

无源RC滤波器“滤除”不需要的信号,因为它们分离并允许仅通过其频率的正弦输入信号,最简单的是无源低通滤波器网络。在低频应用(高达100kHz)中,无源滤波器通常使用简单的RC(电阻-电容)网络构建,而高频滤波器(高于100kHz)通常由RLC(电阻-电感-电容)元件制成。无源滤波器由电阻器、电容器和电感器等无源元件组成,没有放大元件(晶体管、运算放大器等),因此没有信号增益,因此它们的输出电平始终小于输入。滤波器是根据它们允许通过它们的信号的频率范围来命名的,同时阻挡或“衰减”其余部分。

weixin_44448586的博客 1万+

避坑指南:vue-print-nb打印隐藏元素与空白页的那些事儿

本文深入解析了使用vue-print-nb插件时,打印出现空白页及隐藏元素问题的根本原因与解决方案。核心在于理解浏览器打印原理,并通过CSS媒体查询精准控制样式。文章提供了从重置根元素高度、处理隐藏元素到控制分页的完整避坑指南,帮助开发者彻底解决打印样式难题。

weixin_29008691的博客 437

北航软院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

基于YOLOv11的手术器械计数系统:从数据集构建到Web应用部署

m2cai16-tool数据集:包含15种腹腔镜手术器械的标注图像Cholec80数据集:包含80个胆囊切除手术视频,标注了7种器械SurgicalTools数据集:包含超过10,000张手术器械图像,涵盖21类常见器械手术剪(Scissors)止血钳(Hemostat)持针器(Needle Holder)手术刀(Scalpel)镊子(Forceps)拉钩(Retractor)吸引器(Suction)

YOLO 396

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

华为od 面试八股文_Python_05_含答案

华为od 面试八股文_Python_05_含答案

MISAYAONE的博客 2564

系统架构设计师【第1章】: 绪论 (核心总结)

系统架构 (System Architecture)是系统的一种整体的高层次的结构表示,是系统的骨架和根基,也决定了系统的健壮性和生命周期的长短。系统架构设计师是承担系统架构设计的核心角色,他不仅是连接用户需求和系统进一步设计与实现的桥梁,也是系统开发早期阶段质量保证的关键角色。通俗地说,系统架构 (System Architecture)

数据知道的博客 1万+

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

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

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

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

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

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

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、付费专栏及课程。

余额充值