hdoj--2767--Proving Equivalences (scc+缩点)
Proving Equivalences
Time Limit : 4000/2000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 1 Accepted Submission(s) : 1
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 (c), that (c) 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 (c), and that (c) 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?
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.
2
4 0
3 2
1 2
1 3
4
2
/*刚开始是强连通小白,现在稍微明白一点了,入度与出度有点难理解;
现在看来,应该是这样的,入度表示当前的scc上边有几个scc,出度是
当前scc下边有几个scc,如果上边或者下边没有点,这就说明,缩点后
这是一个叶子节点或者根节点。对于这道题来说,我们应该分别统计一下
根节点和叶子节点的个数,取其最大值*/
#include<stdio.h>
#include<string.h>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
using namespace std;
#define MAX 50010
int in[MAX],out[MAX],sumin,sumout;
vector<int>G[MAX];
vector<int>scc[MAX];
struct node
{
int u,v;
int next;
}edge[MAX];
int head[MAX],cnt,scc_cnt,dfs_clock;
int sccno[MAX],low[MAX],dfn[MAX];
bool Instack[MAX];
int m,n;
stack<int>s;
void init()
{
memset(head,-1,sizeof(head));
cnt=0;
}
void add(int u,int v)
{
edge[cnt].u=u;
edge[cnt].v=v;
edge[cnt].next=head[u];
head[u]=cnt++;
}
void getmap()
{
int a,b;
while(m--)
{
scanf("%d%d",&a,&b);
add(a,b);
}
}
void suodian()
{
for(int i=1;i<=scc_cnt;i++)
G[i].clear(),in[i]=0,out[i]=0;//缩点时清空G[i],存放每一个scc
for(int i=0;i<cnt;i++)
{
int u=sccno[edge[i].u];
int v=sccno[edge[i].v];
if(u!=v)
//原图中的u--v现在变成了新图中的u--v,这条路变成了两个scc的链接
G[u].push_back(v),out[u]++,in[v]++;
}
}
void tarjan(int u,int fa)
{
int v;
low[u]=dfn[u]=++dfs_clock;//更新时间戳
s.push(u);//标记u进栈
Instack[u]=true;
for(int i=head[u];i!=-1;i=edge[i].next)
{//遍历u下边的每一个点,同时判断是否遍历过,是否在栈里
v=edge[i].v;
if(!dfn[v])
{
tarjan(v,u);
low[u]=min(low[u],low[v]);
}
else if(Instack[v])
low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u])
//新的scc出现的标志,不好理解的话,可以想象一下一个普通的叶子节点
{
scc_cnt++;//由此可以看出,scc的编号从1开始
scc[scc_cnt].clear();//存放新发现的scc
for(;;)
{
v=s.top();
s.pop();//取出当前scc中的每一个点,放入vector
Instack[v]=false;
sccno[v]=scc_cnt;
scc[scc_cnt].push_back(v);
if(u==v) break;
}
}
}
void solve()
{
sumin=sumout=0;
if(scc_cnt==1)
{
printf("0\n");
}
else
{
for(int i=1;i<=scc_cnt;i++)
{
if(in[i]==0) sumin++;
if(out[i]==0) sumout++;
}
int sum=max(sumin,sumout);
printf("%d\n",sum);
}
}
void find(int l,int r)
{
memset(low,0,sizeof(low));
memset(dfn,0,sizeof(dfn));
memset(sccno,0,sizeof(sccno));
dfs_clock=scc_cnt=0;
for(int i=l;i<=r;i++)
if(!dfn[i])
tarjan(i,-1);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
init();
getmap();
find(1,n);
suodian();
solve();
}
return 0;
}
hdoj--2767--Proving Equivalences (scc+缩点)的更多相关文章
- hdoj 2767 Proving Equivalences【求scc&&缩点】【求最少添加多少条边使这个图成为一个scc】
Proving Equivalences Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 2767 Proving Equivalences 强连通缩点
给出n个命题,m个推导,问最少添加多少条推导,能够使全部命题都能等价(两两都能互推) 既给出有向图,最少加多少边,使得原图变成强连通. 首先强连通缩点,对于新图,每一个点都至少要有一条出去的边和一条进 ...
- HDU 2767 Proving Equivalences (强联通)
pid=2767">http://acm.hdu.edu.cn/showproblem.php?pid=2767 Proving Equivalences Time Limit: 40 ...
- hdu 2767 Proving Equivalences
Proving Equivalences 题意:输入一个有向图(强连通图就是定义在有向图上的),有n(1 ≤ n ≤ 20000)个节点和m(0 ≤ m ≤ 50000)条有向边:问添加几条边可使图变 ...
- HDU 2767 Proving Equivalences(至少增加多少条边使得有向图变成强连通图)
Proving Equivalences Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- HDU 2767 Proving Equivalences (Tarjan)
Proving Equivalences Time Limit : 4000/2000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other ...
- hdu 2767 Proving Equivalences(tarjan缩点)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2767 题意:问最少加多少边可以让所有点都相互连通. 题解:如果强连通分量就1个直接输出0,否者输出入度 ...
- HDU 2767 Proving Equivalences(强连通 Tarjan+缩点)
Consider the following exercise, found in a generic linear algebra textbook. Let A be an n × n matri ...
- hdu2767 Proving Equivalences Tarjan缩点
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- UVALive 4287 Proving Equivalences(缩点)
等价性问题,给出的样例为 a->b的形式,问要实现全部等价(即任意两个可以互相推出),至少要加多少个形如 a->b的条件. 容易想到用强连通缩点,把已经实现等价的子图缩掉,最后剩余DAG. ...
随机推荐
- Last-Modified If-Modified-Since ETag If-None-Match
Last-Modified.If-Modified-Since 有些数据随时都在变化. CNN.com 的主页经常几分钟就更新.另一方面,Google.com 的主页几个星期才更新一次 (当他们上传特 ...
- Python 之 %s字符串、%d整型、%f浮点型
%s string="hello" #%s打印时结果是hello print "string=%s" % string # output: string=hel ...
- AMQP及RabbitMQ
AMQPAMQP协议是一个高级抽象层消息通信协议,RabbitMQ是AMQP协议的实现.它主要包括以下组件: 1.Server(broker): 接受客户端连接,实现AMQP消息队列和路由功能的进程. ...
- Hadoop多节点Cluster
Hadoop多节点集群规划 服务起名称 内网IP HDFS YARN master 192.168.1.155 NameNode ResourceManager slave1 192.168.1.11 ...
- 时序分析:HMM模型(状态空间)
关于HMM模型:时序分析:隐马尔科夫模型 HMM用于手势识别: 训练时每一种手势对应一个HMM-Model,识别率取最大的一个HMM即可. 类似于一个封装的完成多类识别器功能单层网络. 优点: 尤其 ...
- Matlab/Eigen矩阵填充问题
Matlab进行矩阵填充时可以填充空矩阵,相当于空矩阵不存在,例如一下代码: P_RES = [ P_xv P_xvy P_xv*dy_dxv'; P_yxv P_y P_yxv*dy_dxv'; d ...
- FormCollection获取请求数据
public ActionResult Add(FormCollection fm) //通过FormCollection 对象获取表单数据 { string message = "&quo ...
- [转]使用Fiddler进行iOS APP的HTTP/HTTPS抓包
Fiddler不但能截获各种浏览器发出的HTTP请求, 也可以截获各种智能手机发出的HTTP/HTTPS请求.Fiddler能捕获iOS设备发出的请求,比如IPhone, IPad, MacBook. ...
- 在Unity中客户端与服务器端的2种通信方式(Socker)
15:17 2019/5/10 //第一种 using UnityEngine; using System.Collections; //引入库 using System.Net; using Sys ...
- BZOJ 4999: This Problem Is Too Simple! DFS序+LCA+树状数组+离线
Code: #include<bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) , ...