Test instructions
Delete the K-bar, so that the sequence of the dictionary is the largest after the topological sort
Analysis:
Because we require the last topological sequence dictionary to be the largest, we must be greedy to the larger the point of the queue sooner. We define the penetration of point I as Di.
Assuming that the current can also delete the K-bar, then we will always be in the team's di≤k the largest I find out, and its di strip into the Edge are deleted, and then join the topological sequence.
The deletion must be small even large side, because the small side of Dalian in the topological sequence generated by the time it was removed
1#include <iostream>2#include <cstdio>3#include <queue>4#include <vector>5 using namespacestd;6 Const intMAXN =100005;7 intN, M, K, u, v;8vector<int>G[MAXN];9 intC[MAXN], VIS[MAXN], ANS[MAXN];Tenpriority_queue<int>s; One intMain () A { - while(~SCANF ("%d%d%d", &n, &m, &k)) - { the while(!s.empty ()) S.pop (); - for(inti =1; I <= N; i++) G[i].clear (), vis[i] = c[i] =0; - for(inti =1; I <= m; i++) - { +scanf"%d%d", &u, &v); - G[u].push_back (v); +c[v]++; A } at for(inti =1; I <= N; i++) - if(k >=C[i]) s.push (i); - intCNT =0; - while(!s.empty ()) - { - intx =s.top (); S.pop (); in if(C[x] <= k &&!Vis[x]) - { toVIS[X] =1; +K-= C[x], c[x] =0; -ans[cnt++] =x; the for(inti =0; I < g[x].size (); i++) * { $c[g[x][i]]--;Panax Notoginseng if( !C[g[x][i]] S.push (G[x][i]); - } the } + } A for(inti =0; I < cnt-1; i++) printf ("%d", Ans[i]); theprintf"%d\n", ans[cnt-1]); + } -}
HDU 5195-dzy Loves Topological sorting