Proving Equivalences UVA - 12167
题文:https://vjudge.net/problem/UVA-12167
题解:
很明显,先要缩点。然后画一下图就会发现是入度为0的点和出度为0的点取max。
代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
#include <stack>
#define MAXN 50100
using namespace std;
struct edge{
int first;
int next;
int to;
}a[MAXN*];
int low[MAXN],dfn[MAXN],have[MAXN],fa[MAXN];
int in[MAXN],out[MAXN];
int num=,num1=,num2=,n,m;
stack<int> s; void cl(){
memset(low,,sizeof(low));
memset(dfn,,sizeof(dfn));
memset(have,,sizeof(have));
memset(fa,,sizeof(fa));
memset(in,,sizeof(in));
memset(out,,sizeof(out));
memset(a,,sizeof(a));
num1=num2=num=;
} void addedge(int from,int to){
a[++num].to=to;
a[num].next=a[from].first;
a[from].first=num;
} void tarjian(int now){
low[now]=dfn[now]=++num1;
have[now]=;s.push(now);
for(int i=a[now].first;i;i=a[i].next){
int to=a[i].to;
if(!dfn[to]){
tarjian(to);
low[now]=min(low[now],low[to]);
}
else if(have[to]) low[now]=min(low[now],dfn[to]);
}
if(low[now]==dfn[now]){
int u=-;
num2++;
while(u!=now){
u=s.top();s.pop();
have[u]=;
fa[u]=num2;
}
}
} void make(){
for(int now=;now<=n;now++){
for(int i=a[now].first;i;i=a[i].next){
int to=a[i].to;
if(fa[now]!=fa[to]) out[fa[now]]++,in[fa[to]]++;
}
}
} int main()
{
int t;cin>>t;
while(t--){
cl();
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
int x,y;scanf("%d%d",&x,&y);
addedge(x,y);
}
while(!s.empty()) s.pop();
for(int i=;i<=n;i++) if(!dfn[i]) tarjian(i);
make();
int x=,y=;
for(int i=;i<=num2;i++) if(in[i]==) x++;
for(int i=;i<=num2;i++) if(out[i]==) y++;
if(num2==) printf("0\n");
else printf("%d\n",max(x,y));
}
return ;
}
Proving Equivalences UVA - 12167的更多相关文章
- 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 ...
- HDU 2767 Proving Equivalences (Tarjan)
Proving Equivalences Time Limit : 4000/2000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other ...
- UVA12167 Proving Equivalences
UVA12167 Proving Equivalences 题意翻译 题目描述 在数学中,我们常常需要完成若干命题的等价性证明. 例如:有4个命题a,b,c,d,要证明他们是等价的,我们需要证明a&l ...
- HDU 2767 Proving Equivalences (强联通)
pid=2767">http://acm.hdu.edu.cn/showproblem.php?pid=2767 Proving Equivalences Time Limit: 40 ...
- Proving Equivalences (hdu 2767 强联通缩点)
Proving Equivalences Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
随机推荐
- 阿里云 windows frp 远程桌面
环境: 阿里云服务器 server 2008 ,想要被远程访问的终端(本机)是win7 x64 目的:实现在别的地方(家里,出差在外) 用 远程桌面 访问 位于公司内部的电脑 frp 介绍:https ...
- java架构之路-(源码)mybatis基本使用
我们今天先来简单了解一下我们持久层框架,mybatis的使用.而且现在的注解成为趋势,我主要说一下注解方向的使用吧(配置文件也会说) 从使用角度只要是三个部分,mybatis-config.xml,m ...
- 警告:Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
执行Maven Install打包的时候,提示以下警告信息: [WARNING] Using platform encoding (GBK actually) to copy filtered res ...
- Java-HashSet集合中的几种遍历方式
//我们先创建一个set集合 public static void main(String[] args) { Set<Integer> sets = new HashSet<> ...
- 转换地图 (康托展开+预处理+BFS)
Problem Description 在小白成功的通过了第一轮面试后,他来到了第二轮面试.面试的题目有点难度了,为了考核你的思维能量,面试官给你一副(2x4)的初态地图,然后在给你一副(2x4)的终 ...
- 松软科技课堂:SQL-SELECT-INTO语句
SQL SELECT INTO 语句可用于创建表的备份复件. SELECT INTO 语句 SELECT INTO 语句从一个表中选取数据,然后把数据插入另一个表中. SELECT INTO 语句常用 ...
- request对象的方法
request对象封装的是请求的数据,由服务器创建,作为实参传递给Servlet的方法,一个请求对应一个request对象,request对象可以获得请求数据. 1.获取请求行信息 (1)get提交 ...
- 02 (OC)* ViewController 的声明周期
一. UIViewController 的 生命周期 代码 示例 #pragma mark --- life circle // 非storyBoard(xib或非xib)都走这个方法 - (inst ...
- airflow的安装
1.环境准备1.1 安装环境1.2 创建用户2.安装airflow2.1 安装python2.2 安装pip2.3 安装数据库2.4 安装airflow2.4.1 安装主模块2.4.2 安装数据库模块 ...
- 使用express框架创建服务器
上一篇写创建第一个node服务器是基于原始方法写的,express框架的作用就是省掉那些原始代码,直接调用相关的方法就可以了,开发起来简单方便. 一.package.json的配置 首先要进行pack ...