首页 技术 正文
技术 2022年11月9日
0 收藏 887 点赞 3,075 浏览 1084 个字

这道就是明星奶牛,A了一次又一次了,(⊙o⊙)…(⊙o⊙)…

去年pas就打了不下5次,就是强联通缩点,然后求出度为0的块

判断有多个的话就无解,一个就输出块的大小。

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std; const int NN=1e4+,MM=NN*; int n,m,Time=,top=,scc=,ans;
int dfn[NN],low[NN],instack[NN],q[NN],belong[NN],chu[NN];
int cnt=,head[NN],next[MM],rea[MM],skt[NN]; void add(int u,int v)
{
cnt++;
next[cnt]=head[u];
head[u]=cnt;
rea[cnt]=v;
}
void tarjan(int u)
{
low[u]=dfn[u]=++Time;
q[++top]=u,instack[u]=;
for (int i=head[u];i!=-;i=next[i])
{
int v=rea[i];
if (dfn[v]==)
{
tarjan(v);
low[u]=min(low[v],low[u]);
}
else if (instack[v]) low[u]=min(low[u],dfn[v]);
}
if (low[u]==dfn[u])
{
scc++;
int x=-;
while (x!=u)
{
x=q[top--];
instack[x]=;
belong[x]=scc;
++skt[scc];
}
}
}
void rebuild()
{
for (int u=;u<=n;u++)
{
for (int i=head[u];i!=-;i=next[i])
{
int v=rea[i];
if (belong[u]!=belong[v]) chu[belong[u]]=;
}
}
int num=,x=;
for (int i=;i<=scc;i++)
if (chu[i]==) num++,x=i;
if (num!=) ans=;
else ans=skt[x];
printf("%d",ans);
}
int main()
{
scanf("%d%d",&n,&m);
int x,y;
memset(head,-,sizeof(head));
for (int i=;i<=m;i++)
{
scanf("%d%d",&x,&y);
add(x,y);
}
for (int i=;i<=n;i++)
if (dfn[i]==) tarjan(i);
rebuild();
}
下一篇: Python cPickle模块
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,105
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,582
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,429
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,836
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,919