poj 2553 Tarjan

题意:找出一些点,满足,对于其它点,如果他能到的话,他也可以回来,不能到的点,回不回来就无所谓,这就是-离散数学学的,1->1 0->1 0->0 这三种条件才是正确的。

解法:找出初度为0的连通分量

/*
----------------------------------

   Love is more than a word.
   It says so much.
   When I see these four letters,
   I almost feel your touch.
   This is only happened since
   I fell in love with you.
   Why this word does this,
   I haven't got a clue.

                   To My Goddess
                          CY
----------------------------------
*/

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>

#define maxn 5000+5

#define ull unsigned long long
 #define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
 #define REP(i,a,b) for(i=a;i<=b;i++)
  #define rep(i,n) for(i=0;i<n;i++)

#define cle(a) memset(a,0,sizeof(a))
 #define clehead(a) rep(i,maxn)a[i]=-1

/*
  The time of story :
  **  while(1)
    {
         once upon a time,
         there was a mountain,
         on top of which there was a temple,
         in which there was an old monk and a little monk.
         Old monk was telling stories inside the temple.
         What was he talking about?
  **  }

   ÎûÎû
   (*^__^*)
*/

#define sci(a) scanf("%d",&a)
 #define scd(a) scanf("%lf",&a)
  #define pri(a) printf("%d",a)
   #define prie(a) printf("%d\n",a)
    #define prd(a)  printf("%lf",a)
     #define prde(a) printf("%lf\n",a)
      #define pre printf("\n")

#define LL(x) x<<1
 #define RR(x) x<<|1

#define pb push_back
#define mod 90001
#define PI 3.141592657

const ull INF = 1LL << 61;
const int inf =   int(1e5)+10;
const double eps=1e-5;

using namespace std;

struct node
{
    int be;
   int to,w;
   int next;
}edge[maxn*5000];

bool cmp(int a,int b){
    return a>b;
}
int head[maxn];
int m;
int low[maxn],dfn[maxn],stack[maxn],used[maxn];
int cnt=0;
int in[maxn],out[maxn];
void add(int x,int y)
{
    edge[cnt].be=x;
    edge[cnt].to=y;
    edge[cnt++].next=head[x];
    head[x]=(cnt-1);
}
void init()
{
    memset(head,-1,sizeof(head));
    cle(used),cle(low),cle(dfn),cle(in),cle(out);
    m=0;
    cnt=0;
}
int tarbfs(int k,int lay,int &scc_num)
{
    used[k]=1;
    low[k]=lay;
    dfn[k]=lay;
    stack[++m]=k;
    for(int i=head[k];i!=-1;i=edge[i].next)
    {
        if(used[edge[i].to]==0)
        {
            tarbfs(edge[i].to,++lay,scc_num);
        }
        if(used[edge[i].to]==1)
        {
            low[k]=min(low[k],low[edge[i].to]);
        }
    }
    if(dfn[k]==low[k])
    {
        ++scc_num;
        do{
            low[stack[m]]=scc_num;
            used[stack[m]]=2;
        }while(stack[m--]!=k);
    }
    return 0;
}
int main()
{
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,t;
    while(scanf("%d",&n)&&n)
    {
        scanf("%d",&t);
        int i,j;
        init();
        int scc_num=0;
        int lay=1;
        for(i=1;i<=t;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            add(x,y);
        }
        for(i=1;i<=n;i++)
        {
            if(used[i]==0)
            {
                tarbfs(i,lay,scc_num);
            }
        }
      /*  for(i=1;i<=n;i++)
        {
            cout<<low[i]<<" ";
        }
        cout<<endl;*/
        cle(used);
       for(i=0;i<cnt;i++)
       {
           if(low[edge[i].be]!=low[edge[i].to])
           {
               out[low[edge[i].be]]++;
             //  used[low[edge[i].be]]=1;
           }
       }
       for(i=1;i<=scc_num;i++)
       {
           if(out[i]==0)
           {
               used[i]=1;
           }
       }
       for(i=1;i<=n;i++)
       {
           if(used[low[i]])
           {
              printf("%d ",i);
           }
       }
       printf("\n");
    }
    return 0;
}


1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看REAdMe.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看REAdMe.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看READme.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值