给出n个命题,m个推导,问最少添加多少条推导,能够使全部命题都能等价(两两都能互推) 既给出有向图,最少加多少边,使得原图变成强连通. 首先强连通缩点,对于新图,每一个点都至少要有一条出去的边和一条进来的边(这样才干保证它能到随意点和随意点都能到它) 所以求出新图中入度为0的个数,和出度为0的个数,加入的边就是从出度为0的指向入度为0的.这样还会有一点剩余,剩余的就乱连即可了. 所以仅仅要求出2者的最大值就OK. #include <iostream> #include<cstring&…
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 c…
题意: 一个有向图,问最少加几条边,能让它强连通 方法: 1:tarjan 缩点 2:采用如下构造法: 缩点后的图找到所有头结点和尾结点,那么,可以这么构造:把所有的尾结点连一条边到头结点,就必然可以是强连通了.如果说有几个结点不连通,那么让他们的尾结点相互只向对方的头结点就好了. 那么,最后的答案就是,头结点和尾结点中比较小的那个数量. 当然,如果缩点后只有一个点,那么就是0; 代码: #include <cstdio> #include <cstring> #include &…
pid=2767">http://acm.hdu.edu.cn/showproblem.php?pid=2767 Proving Equivalences Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2926    Accepted Submission(s): 1100 Problem Description Conside…
Proving Equivalences 题意:输入一个有向图(强连通图就是定义在有向图上的),有n(1 ≤ n ≤ 20000)个节点和m(0 ≤ m ≤ 50000)条有向边:问添加几条边可使图变成强连通图: 强连通分量:对于分量中的任意两个节点,都存在一条有向的路径(顺序不同,表示的路径不同):说白了,就是任意两点都能形成一个环(但不是说只有一个环) 思路:使用Tarjan算法 (讲解得很好)即可容易地在得到在一个强连通分量中设置每个点所属的强连通分量的标号:即得到所谓的缩点:之后就是合并…
Proving Equivalences Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9296    Accepted Submission(s): 3281 Problem Description Consider the following exercise, found in a generic linear algebra t…
Proving Equivalences Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 3   Accepted Submission(s) : 1 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Consider the follo…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2767 题意:问最少加多少边可以让所有点都相互连通. 题解:如果强连通分量就1个直接输出0,否者输出入度为0的缩点,出度为0的缩点和的最大值 #include <iostream> #include <cstring> #include <cstdio> using namespace std; const int N = 2e4 + 10; const int M = 5e…
http://acm.hdu.edu.cn/showproblem.php?pid=2767 求至少添加多少条边才能变成强连通分量.统计入度为0的点和出度为0的点,取最大值即可. #include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <cstring> #include <algorithm> #include <str…
原题链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2288 题意: 给你一个有向图,问你至少需要添加多少条边,使得整个图强连通. 题解: 就..直接缩点,令缩点后入度为0的点有a个,出度为0的点有b个,答案就是max(a,b) 代码: #include<iostream> #include<cstri…
Proving Equivalences Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4263    Accepted Submission(s): 1510 Problem Description Consider the following exercise, found in a generic linear algebra t…
Proving Equivalences Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9208    Accepted Submission(s): 3257 Problem Description Consider the following exercise, found in a generic linear algebra t…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4635 题意:给你一个n个点m条边的图,问在图不是强连通图的情况下,最多可以向图中添多少条边,若图为原来就是强连通图,输出-1即可: 思路:最后得到的图肯定分为两部分x和y,且两部分均为强连通分量,要么x的点到y的所有点有边,要么,从y的所有点到x的所有点有边:(其中只有入度或出度为0的点才可能成为x或y) 则有         x+y=n  答案为 ans = y*(y-1) + x*(x-1)+…
等价性问题,给出的样例为 a->b的形式,问要实现全部等价(即任意两个可以互相推出),至少要加多少个形如 a->b的条件. 容易想到用强连通缩点,把已经实现等价的子图缩掉,最后剩余DAG.要推出一个方案,YY后取“出度为零”和“入度为零”的点数的较大值. 理由:假定出度为零的点数较多,即是我们通常意义上的树的形式(当然,DAG是图,这里只是类比). 根可以推出其所有子孙,事实上任意一个点都可以推出其子孙,那么只要让该节点推出树根,就可以推出整棵树上所有的节点了.那么多棵树为什么不是相乘呢?,借…
#include<stdio.h> #include<string.h> #define N 21000 struct node { int u,v,next; }bian[N*3]; int head[N],dfn[N],low[N],index,vis[N],stac[N],top,yong,cnt,suo[N],indegree[N],outdegree[N]; void init() { yong=0;index=0;top=0;cnt=0; memset(vis,0,si…
http://acm.hdu.edu.cn/showproblem.php?pid=3639 题意: 有一群孩子正在玩老鹰抓小鸡,由于想当老鹰的人不少,孩子们通过投票的方式产生,但是投票有这么一条规则:投票具有传递性,A支持B,B支持C,那么C获得2票(A.B共两票),输出最多能获得的票数是多少张和获得最多票数的人是谁? 思路: 先强连通缩点反向建图,在计算强连通的时候,需要保存每个连通分支的结点个数. 为什么要反向建图呢?因为要寻找票数最多的,那么肯定是入度为0的点,然后dfs计算它的子节点的…
题意: 给一个有向图,问添加几条边可以使其强连通. 思路: tarjan算法求强连通分量,然后缩点求各个强连通分量的出入度,答案是max(入度为0的缩点个数,出度为0的缩点个数). #include <bits/stdc++.h> #define LL long long #define pii pair<int,int> using namespace std; +; const int INF=0x7f7f7f7f; vector<int> vect[N]; sta…
给一个图,问至少加入�多少条有向边能够使图变成强连通的. 原图是有环的,缩点建图,在该DAG图上我们能够发现,要使该图变成强连通图必须连成环 而加入�最少的边连成环,就是把图上入度为0和出度为0的点连上,那么其它的点就都能够互相到达了 所以答案就是max(入度为0的点,出度为0的点) #include <iostream> #include <cstring> #include <string> #include <cstdio> #include <…
Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4343    Accepted Submission(s): 1541 Problem Description Consider the following exercise, found in a generic linear algebra textbook. Let A be an…
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2767 Proving Equivalences Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description Consider the following exercise, found in a generic linear algebra textbook.…
Proving Equivalences Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3743    Accepted Submission(s): 1374 Problem Description Consider the following exercise, found in a generic linear algebra…
Proving Equivalences 题目链接(点击) 参考博客(点击) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9497    Accepted Submission(s): 3349Problem Description Consider the following exercise, found in a generi…
poj 1236: 题目大意:给出一个有向图, 任务一: 求最少的点,使得从这些点出发可以遍历整张图  任务二: 求最少加多少边 使整个图变成一个强连通分量. 首先任务一很好做, 只要缩点 之后 求 入度为0的点 的个数就好了.   因为 缩点后无环,任何一个 入度不为0的点, 沿着入边 倒着走回去一定可以到达一个入度为0的点. 任务二: 首先给出结论: 如果整个图已经是一个强连通分量,那么答案是0.  否则求出 缩点后入度为0的点和出度为0的点的个数a,b, 答案就是 max(a,b). 今天…
Problem   UVALive - 4287 - Proving Equivalences Time Limit: 3000 mSec Problem Description Input Output Sample Input 2 4 0 3 2 1 2 1 3 Sample Output 4 2 题解:题意就是给出一个有向图,问最少添加几条有向边能够使得整张图强连通,Tarjan缩点是比较容易想到的,之后怎么办,要用到一个结论:如果图中有a个入度为零的点,b个出度为零的点,那么max(a,…
Proving Equivalences Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6006    Accepted Submission(s): 2051 Problem Description Consider the following exercise, found in a generic linear algebra t…
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. If a un-lighting bomb is in or on the border th…
Proving Equivalences Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10665    Accepted Submission(s): 3606 Problem Description Consider the following exercise, found in a generic linear algebra…
Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10    Accepted Submission(s): 3 Problem Description There are N bombs needing exploding.Each bomb has three attributes: exploding radius ri,…
http://acm.hdu.edu.cn/showproblem.php?pid=1269 判断一个图是不是强连通,缩点之后判断顶点数是不是为1即可. #include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <cstring> #include <algorithm> #include <string> #incl…
The Bottom of a Graph Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 10114   Accepted: 4184 Description We will use the following (standard) definitions from graph theory. Let V be a nonempty and finite set, its elements being called ve…