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 ...
随机推荐
- Ubuntu hadoop配置之修改主机名
1.查看主机名的方法 方法1: 在终端输入hostname 方法2: 提示符 liuhongyang@ubuntu:~$ liuhongyang:用户名 ubuntu: 主机名 ~: ...
- Servlet+jsp用户登录加上验证码
最近公司有个项目被客户拿去进行漏洞扫描,发现用户登录太简单,容易被暴力破解.当然发现的问题很多,什么反射型XSS,存储型XSS,敏感信息泄露等等.但是我们今天不讲这么多,就说说如何修复暴力破解的问题. ...
- 互联网寒冬之泪:Android开发程序员,你够优秀吗?
我想每个开发者在学习成长的过程中,在面临技术难题的时候,都有经历过自我怀疑的过程,但是有时候这并不是你的错,大家都经历过如此的过程.我们作为一个开发者,在成长的过程中,总有一些小的胜利和小的沮丧,学着 ...
- Redis的复制(Master/Slave)、主从复制、读写分离 (下)
哨兵模式(就是反客为主的自动版) 能够自动监控主机是否故障,如果故障了根据投票数自动将从机变成主机 1创建哨兵文件 touch sentinel.conf [root@localhost myredi ...
- 从零开始入门 K8s| K8s 的应用编排与管理
作者 | 张振 阿里巴巴高级技术专家 一.资源元信息 1. Kubernetes 资源对象 我们知道,Kubernetes 的资源对象组成:主要包括了 Spec.Status 两部分.其中 Spec ...
- java动态代理之CGLIB实现
动态代理(CGlib 与连接池的案例) Cglib代理: 针对类来实现代理,对指定目标 产生一个子类 通过方法拦截技术拦截所有父类方法的调用. 我们要使用cglib代理必须引入 cglib的jar包 ...
- Elastic Stack 笔记(九)Elasticsearch5.6 集群管理
博客地址:http://www.moonxy.com 一.前言 集群搭建好以后,在日常中就要对集群的使用情况进行监控,对于一个多节点集群,由于网络连接问题,出现宕机.脑裂等异常情况都是有可能发生的.E ...
- TestNG(四) 基本注解BeforeSuite和AfterSuite
package com.course.testng; import org.testng.annotations.*; public class BasicAnnotation { @Test //最 ...
- netty源码解解析(4.0)-22 ByteBuf的I/O
ByteBuf的I/O主要解决的问题有两个: 管理readerIndex和writerIndex.这个在在AbstractByteBuf中解决. 从内存中读写数据.ByteBuf的不同实现主要 ...
- [Boost库] noncopyable——禁止拷贝的类
1.noncopyable允许程序轻松地实现一个禁止拷贝的类,在头文件<boost/noncopyable.hpp>中 2.实现原理很简单:noncopyable的实现就是用了C++中 ...