HDU 1269 裸奔的強聯通分量

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   ar   os   sp   for   

看了別人部落格  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 1000000007using namespace std;typedef struct myedge{    int e,next;}E;E edge[100010];stack <int> st;int head[10010],ct,tim;int ti[10010],lo[10010],ins[10010],n,m;void inithead(){    CL(head,-1);    tim=0;    ct=0;}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]=1;    int p=head[i];    int v;    while(p!=-1)    {        v=edge[p].e;        if(ins[v]==1)        {            lo[i]=min(lo[v],lo[i]);        }        else if(ti[v]==0)        {            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()]=0;            st.pop();        }    }}int main(){    while(scanf("%d %d",&n,&m)!=EOF)    {        if(n==0&&m==0)break;        int i,j,a,b;        inithead();        CL(lo,0);        CL(ti,0);        CL(ins,0);        for(i=0;i<m;i++)        {            scanf("%d %d",&a,&b);            addedge(a,b);        }        targan(1);        int re=0;        for(i=1;i<=n;i++)        {            if(lo[i]==ti[i])re++;        }  //      cout<<re<<endl;        if(re==1)printf("Yes\n");        else printf("No\n");    }    return 0;}

 

HDU 1269 裸奔的強聯通分量

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.