[hdu5195] Segment Tree

Source: Internet
Author: User

Test instructions: To a DAG, you can delete up to K-bar, and find the topological sequence with the largest dictionary order. Idea: Greedy Select the current optional maximum number, while using a line tree maintenance. A node can be selected when and only if there is no edge pointing to it.

1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <map>6#include <queue>7#include <cmath>8#include <vector>9#include <ctime>Ten#include <cctype> One  A using namespacestd; -  - #defineMem0 (a) memset (a, 0, sizeof (a)) the #defineLson L, M, RT << 1 - #defineRson m + 1, R, RT << 1 | 1 - #definedefine_m int m = (L + r) >> 1 - #defineRep (A, b) for (int a = 0; a < b; a++) + #defineLowbit (x) ((x) & (-(x))) - #defineCONSTRUCTINT3 (name, a, B, c) name (int a = 0, int b = 0, int c = 0): A (a), B (b), C (c) {} + #defineConstructInt2 (name, a, b) name (int a = 0, int b = 0): A (a), B (b) {} A  attypedefDoubledb; -typedefLong LongLL; -  - Const intdx[4] = {1,0, -1,0}; - Const intdy[4] = {0, -1,0,1}; - Const intMAXN = 1e5 +7; in Const intMAXM = 1e5 +7; - Const intMD = 1e9 +7; to Const intINF = 1e9 +7; +  -template<classEdge>structGraph { thevector<vector<edge> >adj; *Graph (intN) {adj.clear (); Adj.resize (n +5);} $ Graph () {adj.clear ();}Panax Notoginseng     voidResizeintN) {adj.resize (n +5); } -     voidAddints, Edge e) {Adj[s].push_back (e);} the     voidDelints, Edge e) {Adj[s].erase (Find (ITER (Adj[s]), e)); +vector<edge>&operator[](intT) {returnadj[t];} A }; thegraph<int>G, H; + intX; - structSeg { $     intMINV[MAXN <<2]; $     voidBuildintLintRintRT) { -         if(L = =r) { -MINV[RT] =h[l].size (); the             return ; -         }Wuyi define_m; the build (Lson); - build (Rson); WuMINV[RT] = min (minv[rt <<1], Minv[rt <<1|1]); -     } About     voidUpdateintPintXintLintRintRT) { $         if(L = =r) { -MINV[RT] + =x; -             return ; -         } A define_m; +         if(P <=m) Update (p, x, Lson); the         ElseUpdate (P, x, Rson); -MINV[RT] = min (minv[rt <<1], Minv[rt <<1|1]); $     } the     int Get(intKintLintRintRT) { the         if(L = =r) { theX =Minv[rt]; the             returnl; -         } in define_m; the         if(Minv[rt <<1|1] <= k)return Get(k, Rson); the         return Get(k, Lson); About     } the }; the Seg S; the intMain () { +     //freopen ("In.txt", "R", stdin); -     intN, M, K; the      while(Cin >> n >> M >>k) {Bayi g.adj.clear (); the g.resize (n); the h.adj.clear (); - h.resize (n); -          for(inti =0, u, v; I < m; i++) { thescanf"%d%d", &u, &v); the g.add (U, v); the H.add (V, u); the         } -S.build (1N1); the          for(inti = n; I i--) { the             intDot = S.GetK1N1); theK-=X;94printf"%d%c", Dot, I >=2?' ':'\ n'); theS.update (dot, INF,1N1); the              for(intj =0; J < G[dot].size (); J + +) { theS.update (G[dot][j],-1,1N1);98             } About         } -     }101     return 0;102}
View Code

[hdu5195] Segment Tree

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.