简单tarjan》一道裸题(BZOJ1051)(easy)
这是一道水题,实际考察的是你会不会写强连通分量。。。(在BZOJ上又水了一道题)
Description
Input
Output
一个数,即有多少头牛被所有的牛认为是受欢迎的。
Sample Input
1 2
2 1
2 3
Sample Output
HINT
#include<stdio.h>
#include<string.h>
int head[],F[],w[],ass,stack[],n,point,m,D[],ans;
int min(int x,int y)
{
return x>y?y:x;
}
bool f[];
struct shit{
int aim,next,from;
}e[];
int T,time[],dfn[];
void tarjan(int x)
{
time[x]=dfn[x]=++T;
f[x]=true;
stack[++ass]=x;
for(int k=head[x];k;k=e[k].next)
{
int v=e[k].aim;
if(!time[v])
{
tarjan(v);
dfn[x]=min(dfn[x],dfn[v]);
}
else if(f[e[k].aim])dfn[x]=min(dfn[x],time[v]);
}
if(dfn[x]==time[x])
{
f[x]=false;
while(stack[ass]!=x)
{
w[x]++;
F[stack[ass]]=x;
f[stack[ass--]]=false;
}
ass--;
}
}
void fuck(int x,int y)
{
e[++point].aim=y;
e[point].from=x;
e[point].next=head[x];
head[x]=point;
}
int main()
{
int a,b;
scanf("%d%d",&n,&m);
for(int i=;i<=m;++i)
{
scanf("%d%d",&a,&b);
fuck(a,b);
}
for(int i=;i<=n;++i)F[i]=i,w[i]=;
for(int i=;i<=n;++i)
if(!time[i])tarjan(i);
memset(head,,sizeof(head));
point=;
for(int i=;i<=m;++i)
{
if(F[e[i].from]==F[e[i].aim])continue;
else {
D[F[e[i].from]]++;
fuck(F[e[i].aim],F[e[i].from]);
}
}
for(int i=;i<=n;i++)
if(F[i]==i&&!D[i])ans+=w[i];
printf("%d",ans);
return ;
}
没什么好PS的
简单tarjan》一道裸题(BZOJ1051)(easy)的更多相关文章
- tarjan讲解(用codevs1332(tarjan的裸题)讲解)
主要借助这道比较裸的题来讲一下tarjan这种算法 tarjan是一种求解有向图强连通分量的线性时间的算法.(用dfs来实现) 如果两个顶点可以相互通达,则称两个顶点强连通.如果有向图G的每两个顶点都 ...
- 【填坑】bzoj3224 splay裸题
人生第一道splay不出所料是一道裸题,一道水题,一道2k代码都不到的题 #include <cstdio> ,n,p,q; ],c[][],size[],sp[]; void rot(i ...
- 【二分图裸题】poj1325机器调度
题目大意:有两个机器A和B,A机器有n个模式,B机器有m个模式,两个机器最初在0模式 然后有k个作业,每个作业有三个参数i,a,b i代表作业编号,a和b代表第i作业要么在A机器的a模式下完成[或者] ...
- POJ 2409 Let it Bead(polya裸题)
题目传送:http://poj.org/problem?id=2409 Description "Let it Bead" company is located upstairs ...
- UESTC 1591 An easy problem A【线段树点更新裸题】
An easy problem A Time Limit: 2000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others ...
- 【图灵杯 F】一道简单的递推题(矩阵快速幂,乘法模板)
Description 存在如下递推式: F(n+1)=A1*F(n)+A2*F(n-1)+-+An*F(1) F(n+2)=A1*F(n+1)+A2*F(n)+-+An*F(2) - 求第K项的值对 ...
- LeetCode 第 287 号问题:寻找重复数,一道非常简单的数组遍历题,加上四个条件后感觉无从下手
今天分享的题目来源于 LeetCode 第 287 号问题:寻找重复数. 题目描述 给定一个包含 n + 1 个整数的数组 nums,其数字都在 1 到 n 之间(包括 1 和 n),可知至少存在一个 ...
- Tarjan & LCA 套题题目题解
刷题之前来几套LCA的末班 对于题目 HDU 2586 How far away 2份在线模板第一份倍增,倍增还是比较好理解的 #include <map> #include <se ...
- LCT裸题泛做
①洞穴勘测 bzoj2049 题意:由若干个操作,每次加入/删除两点间的一条边,询问某两点是否连通.保证任意时刻图都是一个森林.(两点之间至多只有一条路径) 这就是个link+cut+find roo ...
随机推荐
- VSCode高效开发插件
VSCode 必装的 10 个高效开发插件 https://www.cnblogs.com/parry/p/vscode_top_ten_plugins.html 本文介绍了目前前端开发最受欢迎的开发 ...
- ZOJ-Big string(服气思维)
个人心得:我在分治上看到的,但是感觉跟分治没关系,一眼想到斐波那契数可以找到此时n的字符串,但是无法精确到字母,题解的思路 真是令人佩服,以BA为基准,然后只要此时的长度大于7那么必然可以减去最大的斐 ...
- admins.py总结比较,转
转:http://blog.csdn.net/pipisorry/article/details/46764495
- Dawn 简单使用
1. install npm install dawn -g 2. create project # 1. Create & Initialize $ dn init -t front # ...
- linux下修改ip地址
1.more /etc/sysconfig/network-scripts/ifcfg-eth0 2.ifconfig eth0 192.168.1.211 netmask 255.255.255. ...
- 使用 Git 来备份 MySQL 数据库
使用 Git 来备份 MySQL 数据库 使用 mysqldump 导出 sql 文件 使用 git pull 提交到仓库 将脚本加入任务管理 mysqldump 导出时需要以下参数. --skip- ...
- bzoj 2159 Crash 的文明世界 && hdu 4625 JZPTREE ——第二类斯特林数+树形DP
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2159 学习材料:https://blog.csdn.net/litble/article/d ...
- build RTK on ubuntu 16.04
RTK-1.4.0 InsightToolkit-4.12.2 ./cmake/nvcc-check.cmake line:86 commentout as #message(FATAL_ERROR ...
- 【openCV学习笔记】【2】读取并播放一段视频
#include <iostream> #include <opencv/highgui.h> int main(int argc, char** argv){ cvNamed ...
- java多线程实现每隔500毫秒输出一个数字
总结:主要是利用多线程来进行控制它输出的速度,而且这里要处理异常,这个异常我是这样处理的 1.首先写完一个for循环后,写这个:Thread.currnetThread().sleep(500); 然 ...