日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hdoj-3342-Legal or Not(拓扑排序)

發布時間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdoj-3342-Legal or Not(拓扑排序) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接

1 /* 2 Name:hdoj-3342-Legal or Not 3 Copyright: 4 Author: 5 Date: 2018/4/11 15:59:18 6 Description: 7 判斷是否存在環 8 */ 9 #include <iostream> 10 #include <queue> 11 #include <vector> 12 #include <cstring> 13 #include <algorithm> 14 using namespace std; 15 const int MAXN = 1e+5; 16 int du[MAXN], n , m, L[MAXN]; 17 vector<int> g[MAXN]; 18 bool topsort() { 19 memset(du, 0, sizeof(du)); 20 for (int i=0; i<n; i++) { 21 for (int j=0; j<g[i].size(); j++) { 22 du[g[i][j]]++; 23 } 24 } 25 int tot = 0; 26 queue<int> Q; 27 for (int i=0; i<n; i++) { 28 if (!du[i]) { 29 Q.push(i); 30 } 31 } 32 while (!Q.empty()) { 33 int x = Q.front(); 34 Q.pop(); 35 L[tot++] = x; 36 for (int j=0; j<g[x].size(); j++) { 37 int t = g[x][j]; 38 du[t]--; 39 if (!du[t]) { 40 Q.push(t); 41 } 42 } 43 } 44 if (tot == n) return 1; 45 return 0; 46 } 47 int main() 48 { 49 while (cin>>n>>m && (m || n)) { 50 memset(L, 0, sizeof(L)); 51 memset(g, 0, sizeof(g)); 52 for (int i=0; i<m; i++) { 53 int a, b; 54 cin>>a>>b; 55 g[a].push_back(b); 56 } 57 if (topsort() == 1) cout<<"YES"<<endl; 58 else cout<<"NO"<<endl; 59 } 60 return 0; 61 }

?

轉載于:https://www.cnblogs.com/evidd/p/8796736.html

總結

以上是生活随笔為你收集整理的hdoj-3342-Legal or Not(拓扑排序)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。