POJ 3180 The Cow Prom(强联通)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
usingnamespace std;
#define INF 0x7ffffff
#define maxn 10005
typedef longlong LL;
#define Min(a,b) (a<b?a:b)
#define MOD 1000000007
int m, n, Time, top, ans;
int Stack[maxn], dfn[maxn], low[maxn];
bool InStack[maxn];
vector<vector<int> > G;
void init()
{
memset(dfn, , sizeof(dfn));
memset(low, , sizeof(low));
ans = Time = top = ;
G.clear();
G.resize(n+);
} void Tarjan(int u)
{
dfn[u] = low[u] = ++Time;
Stack[top++] = u;
InStack[u] = true;
int len = G[u].size(), v, k = ; for(int i=; i<len; i++)
{
v = G[u][i];
if( !low[v] )
{
Tarjan(v);
low[u] = min(low[u], low[v]);
}
elseif( InStack[v] )
low[u] = min(low[u], dfn[v]);
}
if(low[u] == dfn[u])
{
do
{
v = Stack[--top];
k ++;
InStack[u] = false;
}while(u != v);
if(k >= )
ans ++;
}
} void solve()
{
for(int i=; i<=n; i++)
{
if(!low[i])
Tarjan(i);
} printf("%d\n", ans); } int main()
{
while(scanf("%d %d",&n, &m) != EOF)
{
init();
while(m --)
{
int a, b;
scanf("%d %d",&a, &b);
G[a].push_back(b);
}
solve();
}
return0;
}
POJ 3180 The Cow Prom(强联通)的更多相关文章
- poj 3180 The Cow Prom(强联通分量)
http://poj.org/problem?id=3180 The Cow Prom Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 3180 The cow Prom Tarjan基础题
题目用google翻译实在看不懂 其实题目意思如下 给一个有向图,求点个数大于1的强联通分量个数 #include<cstdio> #include<algorithm> #i ...
- poj 3180 The Cow Prom(tarjan+缩点 easy)
Description The N ( <= N <= ,) cows are so excited: it's prom night! They are dressed in their ...
- POJ 3180 The Cow Prom(SCC)
[题目链接] http://poj.org/problem?id=3180 [题目大意] N头牛,M条有向绳子,能组成几个歌舞团?要求顺时针逆时针都能带动舞团内所有牛. [题解] 等价于求点数大于1的 ...
- [poj] 3180 the cow prom
原题 这是一道强连通分量板子题. 我们只用输出点数大于1的强连通分量的个数! #include<cstdio> #include<algorithm> #include< ...
- POJ 2186 Popular cows(Kosaraju+强联通分量模板)
题目链接:http://poj.org/problem?id=2186 题目大意:给定N头牛和M个有序对(A,B),(A,B)表示A牛认为B牛是红人,该关系具有传递性,如果牛A认为牛B是红人,牛B认为 ...
- POJ 2186 Popular Cows(强联通+缩点)
Description Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= ...
- POJ 1904 King's Quest 强联通分量+输入输出外挂
题意:国王有n个儿子,现在这n个儿子要在n个女孩里选择自己喜欢的,有的儿子可能喜欢多个,最后国王的向导给出他一个匹配.匹配有n个数,代表某个儿子和哪个女孩可以结婚.已知这些条件,要你找出每个儿子可以和 ...
- POJ 3592 Instantaneous Transference(强联通分量 Tarjan)
http://poj.org/problem?id=3592 题意 :给你一个n*m的矩阵,每个位置上都有一个字符,如果是数字代表这个地方有该数量的金矿,如果是*代表这个地方有传送带并且没有金矿,可以 ...
随机推荐
- hibernate通过判断参数动态组合Hql语句,生成基本通用查询
// public List find(Station entity) { List reuslt = null; // 字符串辅助类 StringBuffer hql = new StringBuf ...
- 在Java控制台模拟dos命令下操作MySQL
一.导入mysql的驱动:"com.mysql.jdbc.Driver", 必须将mysql的驱动 包(jar文件)导入到本工程中. Class.forName("com ...
- idea+maven
使用IntelliJ IDEA开发SpringMVC网站(一)开发环境 http://my.oschina.net/gaussik/blog/385697 使用IntelliJ IDEA开发Sprin ...
- SQL数据库安装
安装过程中经常出现失败或者提示,那么久要清楚干净所有的数据在重新安装,步骤如下. SQL2008卸载 一.从控制面板卸载 1)点击计算机右下角“开始”,点击“控制面板” 2)点击“卸载程序”. 卸载与 ...
- SQL Server Management Studio的对象资源管理器的使用
1.查看 2.对象资源管理器 3.点到某个表的身上 4.出现以下图片,因为有时动态创建的触发器,刷新表下面的触发器可能不出来,所以来这里面找
- What is SaaS?
SaaS, or Software as a Service, describes any cloud service where consumers are able to access softw ...
- 执行hadoop fs -ls时出现错误RuntimeException: core-site.xml not found
由于暴力关机,Hadoop fs -ls 出现了下图问题: 问题出现的原因是下面红框框里面的东西,我当时以为从另一个节点下载一个conf.cloudera.yarn文件就能解决问题,发现不行啊,于是删 ...
- 2016.7.16equals的使用(一)
class V{ private int a; V(int a){ rhis a=a; } public boolean equals(int a,int b){ if(this.a equals( ...
- 找出整数中第k大的数
一 问题描述: 找出 m 个整数中第 k(0<k<m+1)大的整数. 二 举例: 假设有 12 个整数:data[1, 4, -1, -4, 9, 8, 0, 3, -8, 11, 2 ...
- cos-26上传
在开发中常常需要上传文件,上传文件的方式有很多种,这里有一个cos实现的例子. 首先是要拷贝cos.jar包拷贝到WEB-INF/lib目录下,然后才进行编码. 创建一个可以进行自动重命名的Java文 ...