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的矩阵,每个位置上都有一个字符,如果是数字代表这个地方有该数量的金矿,如果是*代表这个地方有传送带并且没有金矿,可以 ...
随机推荐
- C#,MVC视图中把枚举转成DropdownList
1.拓展EnumHelper public static class EnumHelper { // Get the value of the description attribute if the ...
- 19、XHTML
XHTML 可扩展超文本标签语言(EXtensible HyperText Markup Language). 是一种 W3C 标准. 更严格,更纯净的HTML代码. 目标是取代HTML代码. XHT ...
- PHP 开启报错机制
屏蔽PHP错误提示 方法一:在有可能出错的函数前加@,然后or die("") 如: @mysql_connect(...) or die("Database Conne ...
- 读取xml字符串
string strXml = @"<MessageData><pm_id>10</pm_id><pm_title>这是公司或者产品的名称&l ...
- IOS UIColor 自定义颜色
使用 UIColor定义颜色 和 同 CIColor 与 CGColor 之间的联系.转换 1. 利用UIColor展现 #F6F6F6 这个传统的颜色 #F6F6F6 为一个 16 进制表示的RP ...
- mac 连接linux
1.ssh 通过ssh 的方式直接连接linux ssh name@ip -22 例:ssh zyc@192.168.1.100 -22 这个的前提是linux 要开启ssh 服务 先看一下linu ...
- java 对于url地址的实体符号的处理
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 <dependency> <g ...
- 十大算法---Adaboost
当我们有针对同一数据集有多个不同的分类器模型时,怎样组合它们使预测分类的结果更加准确, 针对这种情况,机器学习通常两种策略. 1 一种是bagging,一种是boosting bagging:随机对样 ...
- 如果数据为null,则转成数据库可识别的DBNULL.Value
// <summary> /// 如果数据为null,则转成数据库可识别的DBNULL.Value /// </summary> /// <param name=&quo ...
- 【随记】解决:VS2010 调试器无法继续继续运行该进程,无法启动调试
今天在调试项目的时候突然出现错误: 按照网上的一些方法弄了后还是同样报错,把本地代码删除后从库上重现拉下来的项目依然报错,到这里就明白不是项目本身问题了,而是VS2010 的问题,经过网上查资料,问同 ...