题意:找出一些点,满足,对于其它点,如果他能到的话,他也可以回来,不能到的点,回不回来就无所谓,这就是-离散数学学的,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;
}