【Luogu】 P1726 上白泽慧音

这个题目名……感觉……很……
很裸的一个tarjan吧……
不说了,上代码(代码是谁)

#include <bits/stdc++.h>
using namespace std;
vector <int> que[51000];
int tim,ans,stc[51000],ps,out[51000],flag,dfn[51000],low[51000],clr[51000],ins[51000],top,color_num,count=0,maxn,rem,an[51000];
void tarjan(int x)
{
    tim++; 
    dfn[x]=tim;
    low[x]=tim;
    ins[x]=1;
    stc[++top]=x;
    for(int i=0;i<que[x].size();i++)
    {
        int tmp=que[x][i];
        if(dfn[tmp]==0)
        {
            tarjan(tmp);
            low[x]=min(low[x],low[tmp]);
        }
        else if(ins[tmp])   low[x]=min(low[x],low[tmp]);
    }
    if(dfn[x]==low[x])
    {
        if(stc[top]==x)
            ps++;
        flag=1;
        ins[x]=0;
        clr[x]=++color_num;
        while(stc[top]!=x)
        {
            flag++;
            clr[stc[top]]=color_num;
            ins[stc[top]]=0;
            top--;
        }
        if(flag>maxn)
            maxn=flag,rem=color_num;
        top--;  
    }
}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int x,y,t;
        cin>>x>>y>>t;
        if(t==1)
        {
            que[x].push_back(y);
        }
        else
        {
            que[x].push_back(y);
            que[y].push_back(x);
        }
    }
    for(int i=1;i<=n;i++)
        if(!dfn[i]) tarjan(i);
    cout<<maxn<<endl;
    for(int i=1;i<=n;i++)
        if(clr[i]==rem) printf("%d ",i);
    return 0;
}

其实写的过程中没出什么错,就是……“tm”居然是关键字……

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值