题目链接:hdu:http:acm.hdu.edu.cnshowproblem.php?pid5195bc(中文):http:bestcoder.hdu.edu.cncontest 题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5195 bc(中文):http://bestcoder.hdu.edu.cn/contests/contest_chineseproble
题目链接:hdu:http:acm.hdu.edu.cnshowproblem.php?pid5195bc(中文):http:bestcoder.hdu.edu.cncontest
题目链接:
hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5195
bc(中文):http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=573 8 9 const int maxn = 1e5 + 10;10 const int INF = 0x3f3f3f3f;11 12 int n, m, k;13 14 struct Node {15 int v, flag;16 Node(int v,int flag=0):v(v),flag(flag){}17 Node() { flag = 0; }18 };19 20 vector head[maxn];21 int ind[maxn],done[maxn];22 23 void init() {24 for (int i = 0; i = 0; i--) {44 if (k >= ind[i]) {45 //将i的父亲ui中,满足uii的边,根本不用删46 k -= ind[i];47 pq.push(i);48 for (int j = 0; j ) {49 Node 50 if (i > nd.v) {51 //把边(i,v)删了,拓扑排序的时候不能再走这条边了52 nd.flag = 1;53 ind[nd.v]--;54 }55 }56 }57 }58 59 vector ans;60 //拓扑排序61 while (!pq.empty()) {62 int u = pq.top(); pq.pop();63 if (done[u]) continue;64 ans.push_back(u);65 done[u] = 1;66 for (int i = 0; i ) {67 Node68 if (done[nd.v]||nd.flag) continue;69 ind[nd.v]--;70 if (ind[nd.v] == 0) pq.push(nd.v);71 }72 }73 74 printf("%d", ans[0]+1);75 for (int i = 1; i " %d", ans[i]+1);76 printf("\n");77 }78 return 0;79 }80 /*81 5 3 182 4 383 1 384 3 285 86 5 3 087 4 388 1 389 3 290 */HDU 5195 DZY Loves Topological Sorting 拓扑排序