HDU 1269 裸奔的强联通分量

看了别人博客  http://blog.csdn.net/jokes000/article/details/7538994

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <string>
#include <queue>
#include <stack>
#include <cstring>
#define CL(a,b) memset(a,b,sizeof(a))
#define ll __int64
#define TEST cout<<"TEST ***"<<endl;
#define INF 0x7ffffff0
#define MOD 1000000007
using namespace std; typedef struct myedge
{
int e,next;
}E;
E edge[];
stack <int> st; int head[],ct,tim;
int ti[],lo[],ins[],n,m; void inithead()
{
CL(head,-);
tim=;
ct=;
} void addedge(int s,int e)
{
edge[ct].e=e;edge[ct].next=head[s];head[s]=ct++;
} void targan(int i)
{
tim++;
ti[i]=tim;lo[i]=tim;
st.push(i);
ins[i]=;
int p=head[i];
int v;
while(p!=-)
{
v=edge[p].e;
if(ins[v]==)
{
lo[i]=min(lo[v],lo[i]);
}
else if(ti[v]==)
{
targan(v);
lo[i]=min(lo[i],lo[v]);
}
p=edge[p].next;
}
if(lo[i]==ti[i])
{
while(!st.empty()&&lo[st.top()]==ti[i])
{
ins[st.top()]=;
st.pop();
}
}
} int main()
{
while(scanf("%d %d",&n,&m)!=EOF)
{
if(n==&&m==)break;
int i,j,a,b;
inithead();
CL(lo,);
CL(ti,);
CL(ins,);
for(i=;i<m;i++)
{
scanf("%d %d",&a,&b);
addedge(a,b);
}
targan();
int re=;
for(i=;i<=n;i++)
{
if(lo[i]==ti[i])re++;
}
// cout<<re<<endl;
if(re==)printf("Yes\n");
else printf("No\n");
}
return ;
}
上一篇:springcloud费话之Eureka集群


下一篇:基于Spring的简易SSO设计