首页 > 编程知识 正文

Peterson图,环形拓扑

时间:2023-05-03 08:34:48 阅读:165065 作者:650

想法:面对每个自己的儿子,只需要跑一次拓扑学就可以了

# include bits/stdc.husingnamespacestd; const int N=110,M=N*N; int n、idx、e[M]、ne[M]、h[N]、d[N]; queueintq; vectorintans; voidadd(inta,int b ) { e[idx]=b,ne[idx]=h[a],h[a]=idx; }void tp () ) for ) intI=1; i=n; I ) if (! d[i] ) q.push(I ); } while (! q.empty () { int x=q.front; q.pop (; ans.push_back(x; for(intI=h[x] ); ~i; I=ne[I](intj=e[I] ); if(-d[j]==0) ) q.push ) j; } } }}int main () ) { cinn; memset(h,-1,sizeof h ); for(intI=1; i=n; I ) { int son; while(Cinson,son ) { add(i ) I,son}; d[son]; }TP (); for(intI=0; ians.size (; I ) coutans[i] '; }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。