http://poj.org/problem?id=3180

英文题以后都不粘贴题面。

大意:求点数大于1的强连通分量个数

#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
inline int read(){
int x=,w=;char ch=;
while(ch<''||ch>''){if(ch=='-')w=-;ch=getchar();}
while(ch>=''&&ch<=''){x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*w;
}
const int maxn=;
int cnt=,head[maxn];
struct node{
int w;
int to;
int nxt;
}edge[];
void add(int u,int v){
cnt++;
edge[cnt].to=v;
edge[cnt].nxt=head[u];
head[u]=cnt;
return;
}
int dfn[maxn];
int low[maxn];
bool instack[maxn];
int dis[maxn];
int ans=;
int t=;
stack<int>q;
void tarjan(int u){
int v;
t++;
dfn[u]=t;
low[u]=t;
q.push(u);
instack[u]=;
for(int i=head[u];i!=;i=edge[i].nxt){
v=edge[i].to;
if(!dfn[v]){
tarjan(v);
low[u]=min(low[u],low[v]);
}else if(instack[v]){
low[u]=min(low[u],dfn[v]);
}
}
if(low[u]==dfn[u]){
int k=;
do{
v=q.top();
q.pop();
instack[v]=;
k++;
}while(v!=u);
if(k>=)ans++;
}
return;
}
int main(){
int n=read();
int m=read();
for(int i=;i<=m;i++){
int u=read();
int v=read();
add(u,v);
}
for(int i=;i<=n;i++){
if(!dfn[i]){
tarjan(i);
}
}
printf("%d\n",ans);
return ;
}

POJ3180:The Cow Prom——题解的更多相关文章

  1. poj3180 The Cow Prom

    The Cow Prom Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2373   Accepted: 1402 Desc ...

  2. 洛谷 P2863 [USACO06JAN]牛的舞会The Cow Prom 题解

    每日一题 day11 打卡 Analysis 好久没大Tarjan了,练习练习模板. 只要在Tarjan后扫一遍si数组看是否大于1就好了. #include<iostream> #inc ...

  3. poj 3180 The Cow Prom(强联通分量)

    http://poj.org/problem?id=3180 The Cow Prom Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  4. bzoj1654 / P2863 [USACO06JAN]牛的舞会The Cow Prom

    P2863 [USACO06JAN]牛的舞会The Cow Prom 求点数$>1$的强连通分量数,裸的Tanjan模板. #include<iostream> #include&l ...

  5. bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 -- Tarjan

    1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 Time Limit: 5 Sec  Memory Limit: 64 MB Description The N (2 & ...

  6. P2863 [USACO06JAN]牛的舞会The Cow Prom

    洛谷——P2863 [USACO06JAN]牛的舞会The Cow Prom 题目描述 The N (2 <= N <= 10,000) cows are so excited: it's ...

  7. luoguP2863 [USACO06JAN]牛的舞会The Cow Prom

    P2863 [USACO06JAN]牛的舞会The Cow Prom 123通过 221提交 题目提供者 洛谷OnlineJudge 标签 USACO 2006 云端 难度 普及+/提高 时空限制 1 ...

  8. 题解【洛谷P2863】 [USACO06JAN]牛的舞会The Cow Prom

    题面 题解 \(Tarjan\)板子题. 统计出大小大于\(1\)的强连通分量数量输出即可. 代码 #include <iostream> #include <cstdio> ...

  9. 题解 P2863 【[USACO06JAN]牛的舞会The Cow Prom】

    题目链接 赤裸裸的板子,就加一个特判就行.直接上代码 #include<stdio.h> #include<algorithm> #include<iostream> ...

随机推荐

  1. 三、并行流与串行流 Fork/Join框架

    一.并行流概念: 并行流就是把一个内容分成多个数据块,并用不同的线程分别处理每个数据块的流. java8中将并行进行了优化,我们可以很容易的对数据进行并行操作.Stream API可以声明性的通过pa ...

  2. 理解Python的装饰器

    看Flask文档时候看到关于cache的装饰器,有这么一段代码: def cached(timeout=5 * 60, key=’view/%s’): def decorator(f): @wraps ...

  3. java对于Redis中jedis的操作

    package com.answer.redis; import java.util.HashMap; import java.util.List; import java.util.Map; imp ...

  4. 如何用istio实现应用的灰度发布

    Istio为用户提供基于微服务的流量治理能力.Istio允许用户按照标准制定一套流量分发规则,并且无侵入的下发到实例中,平滑稳定的实现灰度发布功能. 基于华为云的Istio服务网格技术,使得灰度发布全 ...

  5. Python 函数参数类型大全(非常全!!!)

    Python 函数参数类型大全(非常全!!!) 1.在python编写程序里面具有函数文档,它的主要作用是为了让别人可以更好的理解你的函数,所以这是一个好习惯,访问函数文档的方式是: MyFuncti ...

  6. 167. Add Two Numbers【LintCode by java】

    Description You have two numbers represented by a linked list, where each node contains a single dig ...

  7. 165. Merge Two Sorted Lists【LintCode by java】

    Description Merge two sorted (ascending) linked lists and return it as a new sorted list. The new so ...

  8. 一个简单的页面弹窗插件 jquery.pageMsgFrame.js

    页面弹窗是网站中常用的交互效果,它可以强提示网站的某些信息给用户,或者作用于某些信息的修改等等功能. 这几天在做一个项目的时候,就顺捎把这个插件写一下,栽棵树,自己乘凉吧. 原创博文,转载请注明出处: ...

  9. 查找 二叉树中 k1 到 k2区间的节点

    vector<int> res; int key1, key2; void traverse(TreeNode * root){//采用前序遍历 if(root == NULL) retu ...

  10. VT-x VT-d 虚拟化在win10中的问题

    win10真的是非常非常非常非常非常非常非常非常非常非常坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑坑!!!!!! 自带虚拟Buff不说,我不用竟然会有冲突!!!! 一度让我怀疑,我的CPU VT-x坏掉了!!! ...