日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > Hdoj 5195 DZY Loves Topological Sorting 【拓撲】+【線段樹】

Hdoj 5195 DZY Loves Topological Sorting 【拓撲】+【線段樹】

來源:程序員人生   發布時間:2015-06-05 09:26:13 閱讀次數:2586次

DZY Loves Topological Sorting

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 922 Accepted Submission(s): 269

Problem Description
A topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that for every directed edge (u→v) from vertex u to vertex v, u comes before v in the ordering.
Now, DZY has a directed acyclic graph(DAG). You should find the lexicographically largest topological ordering after erasing at most k edges from the graph.

Input
The input consists several test cases. (TestCase≤5)
The first line, three integers n,m,k(1≤n,m≤105,0≤k≤m).
Each of the next m lines has two integers: u,v(u≠v,1≤u,v≤n), representing a direct edge(u→v).

Output
For each test case, output the lexicographically largest topological ordering.

Sample Input
5 5 2
1 2
4 5
2 4
3 4
2 3
3 2 0
1 2
1 3

Sample Output
5 3 1 2 4
1 3 2

Hint
Case 1.
Erase the edge (2->3),(4->5).
And the lexicographically largest topological ordering is (5,3,1,2,4).

題意:給你n條邊,刪去不多于K條邊,使輸出的字典序最大!!
策略:我們每次都找小于等于當前K的較大的數輸出就行了,
需明白:1,每減去1個入度都是減去1條邊。
2:找到1個點以后,1定要將對應點的入度變成最大值,以防后面還有可能被找到。
代碼:

#include <cstdio> #include <cstring> #include <vector> #include <iostream> #include <algorithm> const int M = 1e5+5; const int INF = 0x3f3f3f3f; using namespace std; int c[M<<2], in[M]; vector<int > m[M]; vector<int > ans; int n, mm, k; void update(int p, int x, int l, int r, int pos){ if(l == r){ c[pos] = x; return ; } int mid = (l+r)>>1; if(p <= mid) update(p, x, l, mid, pos<<1); //left和right都是代表的對應的點。 else update(p, x, mid+1, r, pos<<1|1); c[pos] = min(c[pos<<1], c[pos<<1|1]); } int query(int l, int r, int pos){ if(l == r) return l; int mid = (l+r)>>1; if(c[pos<<1|1] <= k) return query(mid+1, r, pos<<1|1);//每次都是盡可能選比較大的點 return query(l, mid,pos<<1); } void topo(){ for(int i = 0; i < n; ++ i){ int temp = query(1, n, 1); k -= in[temp];//表示去掉幾個點 ans.push_back(temp); update(temp, INF, 1, n, 1); //找到后就要更新 in[temp] = INF; //1定要變成正無窮 for(int i = 0; i < m[temp].size(); ++ i){ int v = m[temp][i]; --in[v]; update(v, in[v], 1, n, 1); } } } int main(){ while(scanf("%d%d%d", &n, &mm, &k) == 3){ for(int i = 0; i <= n; ++ i){ m[i].clear(); in[i] = 0; } int u, v; for(int i = 0; i < mm; ++ i){ scanf("%d%d", &u, &v); ++in[v]; m[u].push_back(v); } for(int i = 1; i <= n; ++ i){ update(i, in[i], 1, n, 1); } ans.clear(); topo(); printf("%d", ans[0]); for(int i = 1; i < n; ++ i) printf(" %d", ans[i]); printf(" "); } return 0; }
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 亚洲 欧美 变态 国产 另类 | 99亚洲| 日韩国产精品久久久久久亚洲 | 国产区一区| 久久免费福利视频 | 中文天堂在线观看 | 精品亚洲一区二区三区 | 成人国产精品156免费观看 | 少妇一级淫片免费看 | 中文字幕av第一页 | 国产一级黄色片视频 | 国产成人精品一区二区三区 | 欧美激情视频一区二区三区 | 日韩视频在线免费 | 国产乱人乱精一区二视频国产精品 | 91av电影网| 91一区二区在线 | 免费一区二区 | 欧美日韩亚洲国内综合网 | 国产精品爱啪在线线免费观看 | 久久久国产精品免费 | 国产黄a | 最新精品在线 | 青青草国产成人av片免费 | 国产精品亚洲第一区在线暖暖韩国 | 国产黄在线观看 | 欧美精品在线一区 | 亚洲视频二 | 国内精品国产三级国产在线专 | 国产精品电影在线观看 | 一区二区三区免费 | 精品一区二区三区蜜桃 | 国产成人精品免费视频 | 91欧美精品成人综合在线观看 | 亚洲影院一区 | 欧美在线视频一区二区 | 美女视频一区二区三区 | 一区二区视频在线观看 | 国产精品久久毛片av大全日韩 | 在线观看毛片网站 | 亚洲一级片|