拓撲排序 poj1094

2021-05-27 22:12:14 字數 899 閱讀 1031

此題題目有點小問題,那也是很多人ac不了的原因:

問題是,當給定的前k項條件能夠確定出大小順序時,即便k項之後出現了矛盾條件,輸出也應該是sorted sequence determined after k relations 後面再輸出排序好的序列!

#include #include using namespace std;

#define size 27

int indegree[size];

int graph[size][size];

int list[size];

int map[size];

int top_sort( int n )

} if (count != n) return 2;

if (multi) return 1;

else return 0;//determined

}int main()

if (!map[vesta] && shown_vertex < n)

if (!map[veend] && shown_vertex < n)

if ( !incon && !deter )

else

else if ( result == 2 )}}

}}

if ( incon )

cout << "inconsistency found after " << mark2 << " relations." << endl;

else if ( deter )

else

cout << "sorted sequence cannot be determined." << endl;

} return 0;

}

POJ 1094 拓撲排序

文章大意是將n個字母排序 n 26 最終必須排成鍊錶式的輸出 一旦確定或者出現環,記錄當前步數,後續輸入無視 加個拓撲排序判斷圖的總結 1 如果輸入的有向圖中的點,不存在入度為0的點,則存在迴路,反過來則不成立 2 如果入隊的點的個數小於輸入的點的個數,則肯定存在迴路 3 如果存在的入度為零的點大於...

POJ 1094 拓撲排序)

拓排 各種判 program p1094 type map3 record indegree array a z of longint map array a z 1.26 of char outdegree array a z of longint end var n,m,i,j,num,valu...

poj 1094 拓撲排序

我居然要講課了!我這麼水,嘖嘖。好好準備呀。要不就死定了。這道題,典型的拓撲排序,n個字母,操作m次,然後看看對不對。看了好久才懂,我真是水呀。題解 每輸入一組條件,就進行一次拓撲排序,看看符不符合,在topsort函式中,先迴圈n次,目的把所有入度為零的點都找到並操作,在每次迴圈裡,先看看有幾個入...