{"id":152,"date":"2010-03-13T14:52:00","date_gmt":"2010-03-13T06:52:00","guid":{"rendered":"http:\/\/localhost\/?p=152"},"modified":"2010-03-13T14:52:00","modified_gmt":"2010-03-13T06:52:00","slug":"haoi2007_popular_cattle","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/wjmzbmr\/?p=152","title":{"rendered":"[HAOI2007]\u53d7\u6b22\u8fce\u7684\u725b"},"content":{"rendered":"<p> <a target=\"_blank\" href=\"http:\/\/61.187.179.132:8080\/JudgeOnline\/showproblem?problem_id=1051\">61.187.179.132:8080\/JudgeOnline\/showproblem<\/a><br \/>\u989d\u3002\u3002\u8fd9\u662f\u5f88\u8001\u7684\u5f3a\u8054\u901a\u9898\u76ee\u4e86\u3002\u521a\u521a\u5f04\u61c2\u4e86Tarjan\u7b97\u6cd5\u3002\u3002\u5c31\u50cf\u5b9e\u8df5\u4e00\u4e0b\u3002\u3002\u7ed3\u679cWA\u4e86<br \/>\u5f88\u4e45\u3002\u3002\u6700\u540e\u53d1\u73b0\u539f\u6765\u662fStack\u641e\u9519\u4e86\u3002\u3002\u771f\u662f\u60b2\u5267\u3002\u3002<br \/>\u5c31\u662f\u6c42\u51fa\u6bcf\u4e2a\u5f3a\u8054\u901a\u5206\u91cf\uff0c\u7136\u540e\u5982\u679c\u5165\u5ea6\u4e3a0\u7684\u5206\u91cf\u53ea\u6709\u4e00\u4e2a\uff0c\u7b54\u6848\u5c31\u662f\u8fd9\u4e2a\u5206\u91cf\u7684\u5927\u5c0f\uff0c\u5426\u5219\u5c31\u662f0<br \/>Code\uff1a<br \/>#include&lt;cstdio&gt;<br \/>#include&lt;iostream&gt;<br \/>#include&lt;algorithm&gt;<br \/>#include&lt;vector&gt;<br \/>#include&lt;stack&gt;<br \/>#define rep(i,n) for(int i=0;i&lt;n;i++)<br \/>#define pb push_back<br \/>using namespace std;<br \/>const int inf=~0U&gt;&gt;1,maxn=10000;<br \/>vector&lt;int&gt; E[maxn];<br \/>typedef vector&lt;int&gt;::iterator it;<br \/>int ord[maxn],low[maxn],cnt=0,id[maxn],snt=0,n,m;<br \/>bool inStack[maxn]={0};<br \/>stack&lt;int&gt; Stack;<br \/>void dfs(int x)<br \/>{<br \/>    ord[x]=low[x]=cnt++;<br \/>    inStack[x]=true;Stack.push(x);<br \/>    for(it i=E[x].begin();i!=E[x].end();++i)<br \/>    {<br \/>        if(ord[*i]==-1)<br \/>            dfs(*i),low[x]=min(low[x],low[*i]);<br \/>        else if(inStack[*i]) low[x]=min(low[x],ord[*i]);<br \/>    }<br \/>    if(ord[x]==low[x])<br \/>    {<br \/>        int u;do{u=Stack.top();Stack.pop();id[u]=snt;inStack[u]=false;}while(u!=x);<br \/>        snt++;<br \/>    }<br \/>}<br \/>int Num[maxn]={0},In[maxn]={0};<br \/>int main()<br \/>{<br \/>    \/\/freopen(&quot;in&quot;,&quot;r&quot;,stdin);<br \/>    cin&gt;&gt;n&gt;&gt;m;int s,t;<br \/>    while(m&#8211;) scanf(&quot;%d %d&quot;,&amp;s,&amp;t),E[t-1].pb(s-1);<br \/>    rep(i,n) ord[i]=-1;<br \/>    rep(i,n)if(ord[i]==-1) dfs(i);<br \/>    rep(i,n){<br \/>        int own=id[i];for(it e=E[i].begin();e!=E[i].end();++e)if(id[*e]!=own) In[id[*e]]++;<br \/>        Num[own]++;<br \/>    }<br \/>    t=0;int ans=0;rep(i,snt)if(In[i]==0) ++t,ans+=Num[i];<br \/>    if(t&gt;1)cout&lt;&lt;0&lt;&lt;endl;<br \/>    else cout&lt;&lt;ans&lt;&lt;endl;<br \/>} <\/p>\n","protected":false},"excerpt":{"rendered":"<p>61.187.179.132:8080\/JudgeOnline\/showproblem\u989d\u3002\u3002\u8fd9\u662f\u5f88\u8001\u7684\u5f3a\u8054\u901a\u9898\u76ee\u4e86\u3002\u521a\u521a\u5f04\u61c2\u4e86Tarjan\u7b97\u6cd5\u3002\u3002\u5c31\u50cf\u5b9e\u8df5\u4e00\u4e0b\u3002\u3002\u7ed3\u679cWA\u4e86\u5f88\u4e45\u3002\u3002\u6700\u540e\u53d1\u73b0\u539f\u6765\u662fStack\u641e\u9519\u4e86\u3002\u3002\u771f\u662f\u60b2\u5267\u3002\u3002\u5c31\u662f\u6c42\u51fa\u6bcf\u4e2a\u5f3a\u8054\u901a\u5206\u91cf\uff0c\u7136\u540e\u5982\u679c\u5165\u5ea6\u4e3a0\u7684\u5206\u91cf\u53ea\u6709\u4e00\u4e2a\uff0c\u7b54\u6848\u5c31\u662f\u8fd9\u4e2a\u5206\u91cf\u7684\u5927\u5c0f\uff0c\u5426\u5219\u5c31\u662f0Code\uff1a#include&lt;cstdio&gt;#include&lt;iostream&gt;#include&lt;algorithm&gt;#include&lt;vector&gt;#include&lt;stack&gt;#define rep(i,n) for(int i=0;i&lt;n;i++)#define pb push_backusing namespace std;const int inf=~0U&gt;&gt;1,maxn=10000;vector&lt;int&gt; E[maxn];typedef vector&lt;int&gt;::iterator it;int ord[maxn],low[maxn],cnt=0,id[maxn],snt=0,n,m;bool inStack[maxn]={0};stack&lt;int&gt; Stack;void dfs(int x){ ord[x]=low[x]=cnt++; inStack[x]=true;Stack.push(x); for(it i=E[x].begin();i!=E[x].end();++i) { if(ord[*i]==-1) dfs(*i),low[x]=min(low[x],low[*i]); else if(inStack[*i]) low[x]=min(low[x],ord[*i]); } if(ord[x]==low[x]) { int u;do{u=Stack.top();Stack.pop();id[u]=snt;inStack[u]=false;}while(u!=x); snt++; }}int Num[maxn]={0},In[maxn]={0};int main(){ \/\/freopen(&quot;in&quot;,&quot;r&quot;,stdin); cin&gt;&gt;n&gt;&gt;m;int s,t; while(m&#8211;) scanf(&quot;%d %d&quot;,&amp;s,&amp;t),E[t-1].pb(s-1); rep(i,n) ord[i]=-1; rep(i,n)if(ord[i]==-1) dfs(i); rep(i,n){ int own=id[i];for(it e=E[i].begin();e!=E[i].end();++e)if(id[*e]!=own) In[id[*e]]++; Num[own]++; } t=0;int [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/152"}],"collection":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=152"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/152\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}