本文共 512 字,大约阅读时间需要 1 分钟。
对于拓扑排序,每次能入队的只有入度为0的点,所以用优先队列即可。
以及,第一组数据日常卡OJ,这组数据跳了一个点,我的程序这个版本也过不了(其实写了另一个版的),稍微改改更正确。#includeusing namespace std;const int maxn=510;vector vec[maxn];int indeg[maxn],seq[maxn],N,M,tot=0;void topo(){ tot=0; priority_queue ,greater > pq; for (int i=1;i<=N;i++) { if (indeg[i]==0) { pq.push(i); } } while (!pq.empty()) { int u=pq.top(); pq.pop(); seq[tot++]=u; for (int i=0;i
转载地址:http://iruen.baihongyu.com/