您当前的位置: 首页 >  ar

钟钟终

暂无认证

  • 2浏览

    0关注

    233博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

强连通分量 (kosaraju算法+tarjan算法)

钟钟终 发布时间:2022-03-01 19:32:16 ,浏览量:2

数组都开得我麻木了。。。。

P2341 [USACO03FALL / HAOI2006] 受欢迎的牛 G

https://www.luogu.com.cn/problem/P2341

#include 

using namespace std;
const int maxn=1e5+5;
int n,m,head[maxn],cnt,dfn[maxn],low[maxn],bl[maxn],tim;
int inq[maxn],v[maxn],nxt[maxn],tol,in[maxn],ans,du[maxn];
stackq;
void add(int u,int v1)
{
    v[++cnt]=v1;
    nxt[cnt]=head[u];
    head[u]=cnt;
}
void tarjan(int u)
{
    dfn[u]=low[u]=++tim;
    q.push(u);
    inq[u]=1;
    for(int i=head[u];i;i=nxt[i])
    {
        int v1=v[i];
        if(!dfn[v1])
        {
            tarjan(v1);
            low[u]=min(low[u],low[v1]);
        }
        else if(inq[v1])
            low[u]=min(low[u],dfn[v1]);
    }
    if(dfn[u]==low[u])
    {
        tol++;int tmp;
        do{
            tmp=q.top();
            q.pop();
            inq[tmp]=0;
            in[tol]++;   //此强连通分量的点点数
            bl[tmp]=tol;  //缩点操作
        }while(tmp!=u);
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i            
关注
打赏
1664378814
查看更多评论
0.0443s