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

APK静态分析(取证角度)——理论部分 APP是指应用程序(Application),是指能够在手机、平板电脑、电脑等移动设备上运行的软件。APP可以帮助用户进行各种功能操作,如社交媒体、游戏、购物、学习、工作等。用户可以通过应用商店或者在线下载安装APP,然后在设备上使用它们。APP的种类非常丰富,能够满足用户不同的需求和兴趣。 阅读详情

相关推荐

基于MS5351的三通道可编程时钟发生器设计

时钟发生器是数字系统时序验证与信号完整性测试的核心基础设备,其原理基于锁相环(PLL)对参考晶振进行倍频与分频控制,通过寄存器配置实现多路独立频率输出。技术价值体现在高精度、低抖动、快速切换与工程可部署性之间取得平衡,尤其适用于FPGA/ASIC参考时钟调试、ADC/DAC采样时钟验证及嵌入式硬件时序裕量评估等场景。本方案采用MS5351三通道时钟芯片与ESP32主控协同架构,在保证LVCMOS输出质量与I²C可编程性的前提下,优化电源噪声抑制、晶体负载匹配和跨板信号完整性,兼顾成本、周期与实测稳定性,为实

weixin_31715353的博客 211

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

必看!wechat-article-exporter:轻松批量下载公众号文章

微信搜索“”关注公众号。在信息爆炸的时代,我们每天都会接触到大量优秀的微信公众号文章。有时候,我们想要将这些精彩的内容保存下来,以便日后回顾或者分享给更多的人。然而,微信公众号并没有提供直接的批量下载功能,这给我们带来了不少困扰。今天,我要给大家分享一款非常实用的软件——wechat-article-exporter,它能够帮助我们轻松地批量下载微信公众号文章,让你不再为文章的保存而烦恼。

王乐平 技术博客 4355

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

两层板如何做阻抗控制呢

两层板如何做阻抗控制呢? 这个问题可能很多人都会碰到,有的人在此等需要做阻抗控制的情况都选择做多层板。诚然,多层板在阻抗控制,EMC等等方面都有着天然的优势。然而,在价格上和周期上,两层板就有着绝对优势了。 对于成本非常敏感而又不是太复杂的产品,尽管对于我们硬件工程师而言,有一堆的理由要求使用多层板。然而在面对毛都不懂的老板“别人能做,你为什么不能做?”这个问题时只得低下我们高傲的头颅。 好...

weixin_42005993的博客 2万+

使用bandersnatch搭建pypi 本地镜像源(20211026)

需求背景:公司内网不能联网,同时开发工作需要各种python的模块,因此需要搭建一个pypi的本地镜像源。 参考网上的方法,总结了大致有下面几种方式搭建pypi本地源: devpi: 企业内网利用devpi搭建pypi私服 - 简书 pip2pi: https://yangfannie.com/1439.html pypiserver: https://zhongneng.github.io/2019/02/16/creat-pip/ bandersnatch:基于bandersnatch搭...

liurizhou的博客 6468

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

【Docker】常见容器问题解决#OCI runtime create failed: container_linux.go:349: starting container process

ERROR: for nginx Cannot start service nginx: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/data/docker-compose/n

liu_chen_yang的博客 5528

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

《人工智能基础》[工具篇2]:ChatBox怎么使用本地模型和知识库配置教程

通过设置-知识库,添加,填入知识库名称、选用的嵌入模型创建好知识库后,点击添加文件按钮+,可以上传本地文件、拖动文件支持上传PDF、DOCX等格式的文档。系统会自动对文档进行处理。批量上传:一次最多上传 50 个文档,总大小不超过 2GB;格式检测:支持 PDF/DOCX/TXT/Markdown,不支持 EXE/RAR 等二进制文件。‌文档类‌图片类‌代码类‌:Python、Java、JavaScript等编程文件‌其他‌:Markdown(用于导出对话记录) ‌。

专注大数据、云计算、人工智能、机器人领域技术传播 2940

OpenClaw 安装失败:npm install 多次报错的完整排错与解决方案

这次问题的最终解决,其实并不复杂,但关键在于思路的转变:从“脚本怎么又失败了”,切换为“npm 在这一层到底失败在哪里”。当我们手动复现安装过程、打开 verbose 日志、直面真实错误栈时,问题就不再是模糊的“安装不了”,而是一个可以被定位、被验证、被修复的具体工程问题。

博客 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

qt实现OCC读取STEP模型并显示(附完整源码)

qt实现OCC读取STEP模型并显示(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 1481

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

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

WINCC7.3破解文件

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

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

Camera2Demo

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

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

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

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

余额充值