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

【fNIRS可视化学习1】基于NIRS-SPM进行光极可视化并计算通道坐标 设头皮上的目标点为P₀(x₀, y₀, z₀),需要在大脑皮层点集S上找到最合适的投影点P'。 阅读详情

相关推荐

AWS-解析mysql binlog同步数据方案

虽然是公有云的鼻祖,AWS在某些产品的实现却太不给力;可能是习惯了阿里云喂到嘴边的感觉,AWS很多方案需要自己折腾,蛋疼!比如这里要讲的mysql数据同步方案。 阿里云产品DTS,点几下就OK了,AWS,只能通过插件安装、配置、调试、蹚坑……,具体就是用msk的debezium插件连接器。没见识过的一脸懵逼,下面说下配置步骤和一些注意的坑。

sdmei 1408

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

基于deepseek本地模型的本地知识库构建

通过以上步骤,你已经成功构建了一个基于 AnythingLLM 和 LM Studio 的本地知识库。这个系统不仅能够高效地存储和检索知识,还能结合强大的语言模型生成准确的回答。你可以根据自己的需求进一步扩展和优化这个系统,比如增加更多的文档格式支持、优化检索算法等。

qq_30178745的博客 1383

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

MediaCreationToolW11:Windows11系统升级与修复利器

在日常使用Windows11系统的过程中,我们可能会遇到一些棘手的问题,比如系统更新时出现异常导致无法成功更新,或者系统本身出现异常需要进行无损修复。此外,当我们的电脑尚未升级到Windows11,而我们又希望进行升级时,一款高效且可靠的工具就显得尤为重要。接下来,MediaCreationToolW11将开始下载Windows11的安装文件,并创建Windows11介质。在“选择你要执行的操作”界面中,选择“ISO文件”。此时,你可以使用你的账户登录系统,并开始使用全新的Windows11系统了。

nntxthml的博客 2407

8.时间序列预测

目标:使用历史数据预测未来的销售额。通过以上步骤,可以在Excel中有效进行预测分析,帮助做出更准确的决策通过考虑不同时期数据的影响,可以显著提高预测的准确性。结合多种方法和模型,可以灵活应对复杂的市场环境和变化。

学习,输出==》再学习再输出 891

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

088、多摄像头跨镜目标追踪 ID 频繁切换?ReID 特征 + 轨迹关联 + 时间约束方案

文章摘要:本文针对多摄像头跨镜目标追踪中ID频繁切换的问题,提出了一种结合ReID特征、轨迹关联和时间约束的综合解决方案。作者分析了ID切换的三个主要原因:ReID特征不稳定、轨迹关联依赖最近邻匹配以及忽略时间约束。通过改进ReID特征提取(多层特征融合)、引入轨迹预测(卡尔曼滤波)和添加时间窗口约束,成功将ID切换率从35%降至3%以下。文章详细分享了实现细节和踩坑经验,为跨摄像头目标追踪提供了实用优化思路。

ai技术增长的博客 169

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

图数据库Neo4j面试内容整理-Neo4j的性能

在执行复杂关系查询时,Neo4j 通过图结构的高效存储和查询机制,能够比传统的关系型数据库提供更快的性能,尤其是在涉及深层关系的查询时。通过合理的配置、优化查询和使用合适的硬件,Neo4j 可以处理大规模的数据集和高并发的查询请求,满足企业级应用的需求。Neo4j 在处理图数据时,通过优化图的存储、查询和遍历等方面,提供了高效的性能,特别适合用于需要处理复杂关系和多层次连接的应用场景,如社交网络、推荐系统、知识图谱等。:Neo4j 会根据查询的结构和数据的分布自动选择最优的查询计划。

不务正业的猿 586

MATLAB与ROS联合仿真——控制类功能模块介绍

MATLAB与ROS联合仿真——控制类功能模块介绍

慕羽★的博客 2353

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 3.x 第56节】再见 Feign?原生 HTTP 接口强势上位,这才是微服务调用的正确姿势!

🏆本文收录于《滚雪球学SpringBoot 3》,专门攻坚指数提升,本年度国内最系统+最专业+最详细(永久更新)。    本专栏致力打造最硬核 SpringBoot3 从零基础到进阶系列学习内容,🚀均为全网独家首发,打造精品专栏,专栏持续更新中…欢迎大家订阅持续学习。 如果想快速定位学习,可以看这篇【SpringBoot3教程导航帖】,你想学习的都被收集在内,快速投入学习!!两不误。    若还想学习更多,可直接前往《滚雪球学SpringBoot(全版本合集)》,涵盖SpringBoot所有版本教学文章

**My Coding Family** 1017

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

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

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

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

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

IEM模型,地表粗糙度模拟

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

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

余额充值