{"id":157,"date":"2010-03-16T15:58:00","date_gmt":"2010-03-16T07:58:00","guid":{"rendered":"http:\/\/localhost\/?p=157"},"modified":"2010-03-16T15:58:00","modified_gmt":"2010-03-16T07:58:00","slug":"vijos_1626_love_in_their_hearts","status":"publish","type":"post","link":"https:\/\/www.shuizilong.com\/wjmzbmr\/?p=157","title":{"rendered":"VIJOS 1626 \u7231\u5728\u5fc3\u4e2d"},"content":{"rendered":"\n<p>\u8fd9\u9053\u9898\u76ee\u5f88\u663e\u7136\u662f\u5f3a\u8fde\u901a\u7684\u9898\u76ee\uff0c\u7528Tarjan\u7b97\u6cd5\u6c42\u51fa\u5f3a\u8fde\u901a\u5206\u91cf\u4e4b\u540e\uff0c\u8981\u6ce8\u610f\u4e00\u4e9b\u7ec6\u8282\uff0c<br \/>\u5355\u4e2a\u4eba\u4e0d\u7b97\u7231\u5fc3\u5929\u4f7f\uff01\u9760\u9760\u9760\u3002\u3002\u6240\u4ee5\u5f3a\u8fde\u901a\u5206\u91cf\u8981\u7279\u5224\u7684\u3002<br \/>\u5f88\u663e\u7136\u5982\u679c\u5165\u5ea6\u4e3a0\u7684\u5f3a\u8fde\u901a\u5206\u91cf\u67092\u4e2a\u6216\u4ee5\u4e0a\uff0c\u5c31\u4e0d\u884c\u4e86\u3002<br \/>\u800c\u4e14\u5982\u679c\u8fd9\u4e2a\u5206\u91cf\u662f\u4e00\u4e2a\u4eba\u7684\u8bdd\uff0c\u8fd8\u662f-1\u56e7\u3002\u3002\u6211\u57fa\u672c\u9760STL\u3002\u3002\u771f\u723d\u997f(*^__^*) <br \/>\u5e78\u597d\u6837\u4f8b\u5f88\u5f3a\u5927\uff0c1AC\u4e86(*^__^*) <br \/>Code\uff1a<\/p>\n<p>#include&lt;iostream&gt;#include&lt;cstdio&gt;#include&lt;algorithm&gt;#include&lt;cmath&gt;#include&lt;cstdlib&gt;#include&lt;cstring&gt;#include&lt;string&gt;#include&lt;vector&gt;#include&lt;set&gt;#include&lt;queue&gt;#include&lt;map&gt;#define rep(i,n) for(int i=0;i&lt;n;i++)#define For(i,a,b) for(int i=a;i&lt;=b;i++)#define tr(i,x) for(typeof(x.begin()) i=x.begin();i!=x.end();i++)#define all(x) x.begin(),x.end()#define pb push_backusing namespace std;typedef vector&lt;int&gt; vi;typedef vector&lt;vi&gt; vvi;typedef pair&lt;int,int&gt; ii;const int inf=~0U&gt;&gt;1,maxn=1000;int n,m;vvi E;vi ord,low,inStack,Stack,id;int cnt=0,snt=0;int dfs(int x){    ord[x]=low[x]=++cnt;    inStack[x]=true;Stack.pb(x);    tr(i,E[x])        if(!ord[*i]) low[x]=min(low[x],dfs(*i));        else if(inStack[*i]) low[x]=min(low[x],ord[*i]);    if(ord[x]==low[x])    {        int u;do{u=Stack.back();Stack.pop_back();id[u]=snt;inStack[u]=false;}while(u!=x);        snt++;    }    return low[x];}void Init(){    cin&gt;&gt;n&gt;&gt;m;int s,t;    E.resize(n);    while(m&#8211;)    {        scanf(&quot;%d %d&quot;,&amp;s,&amp;t);        E[t-1].pb(s-1);    }}void Work(){    vi In,Num;    ord=low=inStack=id=vi(n,0);    rep(i,n)if(!ord[i])dfs(i);    In=Num=vi(snt,0);    rep(i,n)tr(e,E[i]) if(id[i]!=id[*e]) In[id[*e]]++;    rep(i,n) Num[id[i]]++;    int t=0;    rep(i,snt)if(Num[i]&gt;1) ++t;    cout&lt;&lt;t&lt;&lt;endl;    if(count(all(In),0)&gt;1) cout&lt;&lt;-1&lt;&lt;endl;    else    {        int ans=find(all(In),0)-In.begin();        if(Num[ans]==1){cout&lt;&lt;-1&lt;&lt;endl;return;}        rep(i,n)if(id[i]==ans)cout&lt;&lt;i+1&lt;&lt;&quot; &quot;;        cout&lt;&lt;endl;    }}int main(){    \/\/freopen(&quot;in&quot;,&quot;r&quot;,stdin);    Init();    Work();} <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u9053\u9898\u76ee\u5f88\u663e\u7136\u662f\u5f3a\u8fde\u901a\u7684\u9898\u76ee\uff0c\u7528Tarjan\u7b97\u6cd5\u6c42\u51fa\u5f3a\u8fde\u901a\u5206\u91cf\u4e4b\u540e\uff0c\u8981\u6ce8\u610f\u4e00\u4e9b\u7ec6\u8282\uff0c\u5355\u4e2a\u4eba\u4e0d\u7b97\u7231\u5fc3\u5929\u4f7f\uff01\u9760\u9760\u9760\u3002\u3002\u6240\u4ee5\u5f3a\u8fde\u901a\u5206\u91cf\u8981\u7279\u5224\u7684\u3002\u5f88\u663e\u7136\u5982\u679c\u5165\u5ea6\u4e3a0\u7684\u5f3a\u8fde\u901a\u5206\u91cf\u67092\u4e2a\u6216\u4ee5\u4e0a\uff0c\u5c31\u4e0d\u884c\u4e86\u3002\u800c\u4e14\u5982\u679c\u8fd9\u4e2a\u5206\u91cf\u662f\u4e00\u4e2a\u4eba\u7684\u8bdd\uff0c\u8fd8\u662f-1\u56e7\u3002\u3002\u6211\u57fa\u672c\u9760STL\u3002\u3002\u771f\u723d\u997f(*^__^*) \u5e78\u597d\u6837\u4f8b\u5f88\u5f3a\u5927\uff0c1AC\u4e86(*^__^*) Code\uff1a #include&lt;iostream&gt;#include&lt;cstdio&gt;#include&lt;algorithm&gt;#include&lt;cmath&gt;#include&lt;cstdlib&gt;#include&lt;cstring&gt;#include&lt;string&gt;#include&lt;vector&gt;#include&lt;set&gt;#include&lt;queue&gt;#include&lt;map&gt;#define rep(i,n) for(int i=0;i&lt;n;i++)#define For(i,a,b) for(int i=a;i&lt;=b;i++)#define tr(i,x) for(typeof(x.begin()) i=x.begin();i!=x.end();i++)#define all(x) x.begin(),x.end()#define pb push_backusing namespace std;typedef vector&lt;int&gt; vi;typedef vector&lt;vi&gt; vvi;typedef pair&lt;int,int&gt; ii;const int inf=~0U&gt;&gt;1,maxn=1000;int n,m;vvi E;vi ord,low,inStack,Stack,id;int cnt=0,snt=0;int dfs(int x){ ord[x]=low[x]=++cnt; inStack[x]=true;Stack.pb(x); tr(i,E[x]) if(!ord[*i]) low[x]=min(low[x],dfs(*i)); else if(inStack[*i]) low[x]=min(low[x],ord[*i]); if(ord[x]==low[x]) { int u;do{u=Stack.back();Stack.pop_back();id[u]=snt;inStack[u]=false;}while(u!=x); snt++; } return low[x];}void Init(){ cin&gt;&gt;n&gt;&gt;m;int s,t; E.resize(n); while(m&#8211;) { [&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\/157"}],"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=157"}],"version-history":[{"count":0,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=\/wp\/v2\/posts\/157\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuizilong.com\/wjmzbmr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}