拓撲排序模板

2021-09-25 13:43:38 字數 1385 閱讀 9038

1.二維陣列+佇列

# include# include# includeusing namespace std;

const int maxn=510;

int in_deg[maxn];

int ans[maxn];

int n,m;

int x[maxn][maxn];

void topsort()

} int cnt=0;

while(!q.empty())

} } }

if(cnt!=n)

} topsort();

} return 0;

}

2.佇列+vertor

# include# include# include# includeusing namespace std;

const int maxn=510;

vectorvec[maxn];

int in_deg[maxn];

int ans[maxn];

int n,m;

int x[maxn][maxn];

void topsort()

} int cnt=0;

while(!q.empty())

topsort();

} return 0;

}

阿里雲建站—為企業提供網際網路「快」服務

2023年因為一場突如其來的疫情,不少企業受到了嚴重衝擊,疫情的衝擊力對傳統「純線

下」行業的危害最大,網際網路女皇瑪麗·公尺克(marymeeker)4月17日發布了著名的年度互

聯網趨勢報告,報告中指出:擁有強大的網際網路線上線下融合能力的企業在疫情中的表現最好,

線上線下融合的趨勢已經存在一段時間了,但是疫情讓這種需求變得更加的迫切。

如果你的企業完全依附於傳統的、純線下的經驗模式,那麼在2023年你將「必死無疑」,

一場巨大的,前所未有的網際網路革命已經到來!

阿里雲建站為了助力各行各業復工復產,疫情期間「馬不停蹄」為數以萬計的企業快速完成

建站,為他們朝著「線上線下融合」或者「純線上」的網際網路經營模式邁進,打下了堅實的基礎。

「雲·速成美站」模板建站1天就能上線,不懂技術沒關係,打字就能建**。千套**模

板免費提供,百元就能建官網,一價全包,無任何**消費。

「雲·企業官網」定製建站1周就能上線,高階量身定製建站,千元建官網無需自己動手,

建站專家1對1**策劃及設計,專業省心之選。

疫情,是一場大浪淘沙,每一次危機背後都隱藏著機會,危機越大,機會也越大。大環境

已經改變,如果你不努力不去改變來迎合這個大環境,那你必將被淘汰。

阿里雲助力企業建站,優惠多多,福利多多,詳情如下鏈結

拓撲排序模板

include include include include include using namespace std const int maxn 30 int head maxn ip,indegree maxn int n,m,seq maxn struct note edge maxn ma...

模板 拓撲排序

拓撲排序 將 小於 關係看做有向圖,形成一條排好序的關係,可能不唯一。queue實現,vector儲存 const int maxn 10005 int in maxn sum,n,m,fa maxn vectorg maxn void init void toposort 按字典序輸出 改為pri...

拓撲排序模板

演算法步驟 1.從aov網中選擇乙個沒有前驅的頂點 該定點的入度為0 並且輸出它 2.從aov網中選刪除該頂點,並且刪除以該頂點為尾的全部有向邊。3.重複上述兩步,知道剩餘的網中不再存在沒有直接前驅的頂點為止。hdu1285 include include include include inclu...