HDU2767 Proving Equivalences
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5742 Accepted Submission(s): 1973
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?
* 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.
* One line with the minimum number of additional implications that
need to be proved in order to prove that all statements are equivalent.
4 0
3 2
1 2
1 3
2
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- #include<vector>
- #include<cstring>
- using namespace std;
- const int mxn=;
- int top,stack[mxn];
- bool inst[mxn];
- int cnt,dnow;
- int dfn[mxn],low[mxn];
- int belone[mxn],in[mxn],out[mxn];
- vector<int> e[mxn];
- void clear(){
- cnt=;dnow=;top=;
- memset(dfn,-,sizeof(dfn));
- memset(inst,false,sizeof(inst));
- memset(in,,sizeof in);
- memset(out,,sizeof out);
- for(int i=;i<mxn;i++) e[i].clear();
- }
- int n,m;
- void tarjan(int s){
- int v=,i;
- dfn[s]=++dnow;
- low[s]=dfn[s];
- inst[s]=true;
- stack[++top]=s;
- int si=e[s].size();
- for(i=;i<si;i++){
- v=e[s][i];
- if(dfn[v]==-){
- tarjan(v);
- low[s]=min(low[v],low[s]);
- }
- else if(inst[v]){
- low[s]=min(dfn[v],low[s]);
- }
- }
- if(dfn[s]==low[s]){
- cnt++;
- do{
- v=stack[top--];
- belone[v]=cnt;
- inst[v]=false;
- }while(s!=v);
- }
- return;
- }
- void calc(){
- if(cnt==){
- printf("0\n");return;
- }
- int i,j;
- for(i=;i<=n;i++){
- for(j=;j<e[i].size();j++){
- int v=e[i][j];
- if(belone[i]!=belone[v]){
- in[belone[v]]++;
- out[belone[i]]++;
- }
- }
- }
- int idg=,odg=;
- for(i=;i<=cnt;i++){
- if(!in[i])idg++;
- if(!out[i])odg++;
- }
- printf("%d\n",max(idg,odg));
- return;
- }
- int main(){
- int T;
- scanf("%d",&T);
- while(T--){
- scanf("%d%d",&n,&m);
- if(!m){
- if(n==)printf("0\n");
- else printf("%d\n",n);
- continue;
- }
- clear();
- int i,j;
- int u,v;
- for(i=;i<=m;i++){
- scanf("%d%d",&u,&v);
- e[u].push_back(v);
- }
- for(i=;i<=n;i++){
- if(dfn[i]==-)tarjan(i);
- }
- calc();
- }
- return ;
- }
HDU2767 Proving Equivalences的更多相关文章
- HDU2767 Proving Equivalences(加边变为强联通图)
Proving Equivalences Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu2767 Proving Equivalences Tarjan缩点
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- hdu2767 Proving Equivalences --- 强连通
给一个图,问至少加入�多少条有向边能够使图变成强连通的. 原图是有环的,缩点建图,在该DAG图上我们能够发现,要使该图变成强连通图必须连成环 而加入�最少的边连成环,就是把图上入度为0和出度为0的点连 ...
- hdu2767 Proving Equivalences,有向图强联通,Kosaraju算法
点击打开链接 有向图强联通,Kosaraju算法 缩点后分别入度和出度为0的点的个数 answer = max(a, b); scc_cnt = 1; answer = 0 #include<c ...
- hdu 2767 Proving Equivalences
Proving Equivalences 题意:输入一个有向图(强连通图就是定义在有向图上的),有n(1 ≤ n ≤ 20000)个节点和m(0 ≤ m ≤ 50000)条有向边:问添加几条边可使图变 ...
- hdoj 2767 Proving Equivalences【求scc&&缩点】【求最少添加多少条边使这个图成为一个scc】
Proving Equivalences Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- Proving Equivalences(加多少边使其强联通)
Proving Equivalences Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- UVALive - 4287 - Proving Equivalences(强连通分量)
Problem UVALive - 4287 - Proving Equivalences Time Limit: 3000 mSec Problem Description Input Outp ...
- HDU 2767 Proving Equivalences(至少增加多少条边使得有向图变成强连通图)
Proving Equivalences Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
随机推荐
- ATM-lib-common
import logging.configfrom conf import settingsfrom core import src def get_logger(name): logging.con ...
- 【函数应用】PHP中关于URL的函数处理
一,函数介绍 1.解析HTTP头信息:get_header() array get_headers ( string 目标URL [, int $format = 0 [如果将可选的 format 参 ...
- 15.VUE学习之-表单中使用key唯一令牌解决表单值混乱问题
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- pycharm配置Git托管
利用Pycharm和github管理代码转载https://www.cnblogs.com/feixuelove1009/p/5955332.html git教程--廖雪峰git教程 转载https ...
- DFS:BZOJ1085-骑士精神
题目: 1085: [SCOI2005]骑士精神 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1461 Solved: 796 [Submit][ ...
- Python文件与异常处理
文件读写 使用python的BIF(build in function)open()进行文件读写操作 # 1.打开文件 data = open(file_name,'w') # 读取模式有很多种,主要 ...
- How to check if Visual Studio 2005 SP1 is installed
How to check if Visual Studio 2005 SP1 is installed Check the following registry key. HKEY_LOCAL_MAC ...
- 分分钟教你做出自己的新闻阅读APP
分分钟教你做出自己的新闻阅读APP 引子 曾经不小心发现了一些好的看新闻的网站,但是电脑又不是随身携带,因此想要下载一个这个网站的手机APP来看新闻,但是问题来了,这个网站根本没有做Android端! ...
- JWT实现token的生成和认证demo
上篇写到对JWT的理解,这篇写一个小的demo来实践下 Github:https://github.com/wuhen152033/token/tree/dev 简介 本次的demo是基于Spring ...
- 【LeetCode】Implement strStr()(实现strStr())
这道题是LeetCode里的第28道题. 题目描述: 实现 strStr() 函数. 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle ...