CCF 认证4
题意:求强联通分量
Tarjan算法
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<memory.h>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<map>
#define clc(a,b) memset(a,b,sizeof(a))
typedef long double ld;
typedef long long ll;
const int N = ;
const double eps=1e-;
const int inf=-;
const int maxn=1e5+;
const int num=;
const double Pi=acos(-);
using namespace std; struct gragh
{
int to;
int next;
} V[num]; bool instack[num]= {false};
int low[num]= {},DFN[num]= {},Stap[num]= {},Belong[num]= {};
int answer=;
int Dindex,stop,Bcnt;
int head[num];
int edge; void add(int a,int b)
{
V[edge].to=b;
V[edge].next=head[a];
head[a]=edge++; }
void tarjan(int u)
{
int v;
DFN[u]=low[u]=++Dindex;
instack[u]=true;
Stap[stop++]=u;
for(int i=head[u]; i!=-; i=V[i].next)
{
v=V[i].to;
if(!DFN[v])
{
tarjan(v);
if(low[v]<low[u])
low[u]=low[v];
}
else if(instack[v]&&DFN[v]<low[u])
low[u]=DFN[v];
}
if(DFN[u]==low[u])
{
int sum=;
Bcnt++;
do
{
v=Stap[--stop];
instack[v]=false;
Belong[v]=Bcnt;
sum++;
}
while(v!=u);
cout<<sum<<endl;
if(sum!=)
answer+=(sum*(sum-))/;
}
}
void solve(int N)
{
stop=Bcnt=Dindex=;
// clc(DFN,0);
for(int i=; i<=N; i++)
if(!DFN[i])
tarjan(i);
} int main()
{
int n,m;
int a,b;
cin>>n>>m;
clc(head,-);
edge=;
for(int i=; i<m; i++)
{
cin>>a>>b;
add(a,b);
}
solve(n);
cout<<answer<<endl;
return ;
}
CCF 认证4的更多相关文章
- CCF认证历年试题
CCF认证历年试题 不加索引整理会死星人orz 第一题: CCF201712-1 最小差值(100分) CCF201709-1 打酱油(100分) CCF201703-1 分蛋糕(100分) CCF2 ...
- 小明种苹果(续)第十七次CCF认证
小明种苹果(续)第十七次CCF认证 题目 原题链接 ](http://118.190.20.162/view.page?gpid=T93) 很高心,在现在CCF CSP可以下载自己当时的答卷了,也就是 ...
- CCF认证(1)
#include <iostream> #include <windows.h> using namespace std; typedef struct letter{ int ...
- CCF 认证
题意:字符串替换 string+map的应用 #include<iostream> #include<stdio.h> #include<stdlib.h> #in ...
- CCF认证考试——折点计数
描述:简单题 #include<iostream> using namespace std; int main() { ], n, count = ; cin >> n; ; ...
- CCF认证之——相反数
这道题目非常简单! #include<iostream> using namespace std; int main() { ],n,count=; cin >> n; ; i ...
- ccf认证 201709-4 通信网络 java实现
试题编号: 201709-4 试题名称: 通信网络 时间限制: 1.0s 内 ...
- ccf认证模拟题之三---最大的矩形
问题描述 在横轴上放了n个相邻的矩形,每个矩形的宽度是1,而第i(1 ≤ i ≤ n)个矩形的高度是hi.这n个矩形构成了一个直方图.例如,下图中六个矩形的高度就分别是3, 1, 6, 5, 2, 3 ...
- CCF认证201712-2游戏
问题描述 有n个小朋友围成一圈玩游戏,小朋友从1至n编号,2号小朋友坐在1号小朋友的顺时针方向,3号小朋友坐在2号小朋友的顺时针方向,……,1号小朋友坐在n号小朋友的顺时针方向. 游戏开始,从1号小朋 ...
随机推荐
- js按钮点击展开收起
$('.tab').click(function(){ var index = $('.tab').index(this), //缓存第一次点击的li的索引值 ele = $(this).find(' ...
- The 5th Zhejiang Provincial Collegiate Programming Contest------ProblemA:Accurately Say "CocaCola"!
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2965 题意:一群人玩过“7”的游戏,有7的数字或者7的倍数就要喊“coca ...
- spoj 95
栈应用 ...... 水题 #include<cstdio> #include<cstdlib> #include<cstring> #include<alg ...
- pthread_create()之前的属性设置
一.pthread_create()之前的属性设置1.线程属性设置我们用pthread_create函数创建一个线程,在这个线程中,我们使用默认参数,即将该函数的第二个参数设为NULL.的确,对大多数 ...
- DJANGO和UIKIT结合,作一个有进度条的无刷新上传功能
以前作的上传,在糙了,所以在用户体验上改进一下. 同时,结合DJANGO作定位上传. 这其中分两步进行,第一次上传到TMP目录下, 第二次,将TMP下的文件转移到标准目录下. form.py file ...
- linux bash_profile和.bashrc区别
经常在一些技术类的文章中提到修改bash_profile和.bashrc这两个文件,也算是使用频率比较高的两个文件吧,但实现同样一个功能,有的教程里说修改bash_profile这个文件,有的教程里却 ...
- 落叶枫桥LOGO
LOGO
- Ubuntu 学习笔记
1. ubuntu开启root账号,设置分配很简单,只要为root设置一个root密码就行了: $ sudo passwd root 之后会提示要输入root用户的密码,连续输入root密码,再使 ...
- 15个必知的Android开发者选项
Android开发者选项,看起来很简单的事情,其实很多同学对它了解得不够,Google用心良苦得为我们设计了这么多小开关都是有它的作用的,今天也花了点时间,过了一遍全部的30多个开关,从中整理出15个 ...
- ActiveMQ之 TCP通讯机制
ActiveMQ支持多种通讯协议TCP/UDP等,我们选取最常用的TCP来分析ActiveMQ的通讯机制.首先我们来明确一个概念: 客户(Client):消息的生产者.消费者对ActiveMQ来说都 ...