传送门

题意简述:给出一张DAGDAGDAG,要求删去不超过kkk条边问最后拓扑序的最大字典序是多少。


思路:贪心帮当前不超过删边上限且权值最大的点删边,用线段树维护一下每个点的入度来支持查询即可。

注意要在选点的时候更新后继的入度

代码:

#include<bits/stdc++.h>
#define ri register int
using namespace std;
inline int read(){
	int ans=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans;
}
const int N=1e5+5,inf=1e9;
int n,m,k,du[N];
bool vis[N];
vector<int>e[N],ans[N];
namespace SGT{
	#define lc (p<<1)
	#define rc (p<<1|1)
	#define mid (T[p].l+T[p].r>>1)
	struct Node{int l,r,mn;}T[N<<2];
	inline void pushup(int p){T[p].mn=min(T[lc].mn,T[rc].mn);}
	inline void build(int p,int l,int r){
		T[p].l=l,T[p].r=r;
		if(l==r){T[p].mn=du[l];return;}
		build(lc,l,mid),build(rc,mid+1,r),pushup(p);
	}
	inline void update(int p,int k){
		if(T[p].l==T[p].r){T[p].mn=du[T[p].l];return;}
		k<=mid?update(lc,k):update(rc,k),pushup(p);
	}
	inline int query(int p,int k){
		if(T[p].l==T[p].r)return T[p].l;
		return T[rc].mn<=k?query(rc,k):query(lc,k);
	}
}
int main(){
	while(~scanf("%d%d%d",&n,&m,&k)){
		for(ri i=1;i<=n;++i)e[i].clear(),du[i]=0;
		for(ri i=1,u,v;i<=m;++i)u=read(),v=read(),e[u].push_back(v),++du[v];
		SGT::build(1,1,n);
		for(ri i=1;i<=n;++i){
			int x=SGT::query(1,k);
			k-=du[x],du[x]=inf,SGT::update(1,x);
			for(ri i=0,v;i<e[x].size();++i)if(du[v=e[x][i]]^inf)--du[v],SGT::update(1,v);
			if(i==n)cout<<x<<'\n';
			else cout<<x<<' ';
		}
	}
	return 0;
}

2019.01.22 hdu5195 DZY Loves Topological Sorting(贪心+线段树)的更多相关文章

  1. 2019.01.22 bzoj3333: 排队计划(逆序对+线段树)

    传送门 题意简述:给出一个序列,支持把ppp~nnn中所有小于等于apa_pap​的'扯出来排序之后再放回去,要求动态维护全局逆序对. 思路:我们令fif_ifi​表示第iii个位置之后比它大的数的个 ...

  2. hdu.5195.DZY Loves Topological Sorting(topo排序 && 贪心)

    DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 ...

  3. hdu 5195 DZY Loves Topological Sorting (拓扑排序+线段树)

    DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 ...

  4. hdu 5195 DZY Loves Topological Sorting 线段树+拓扑排序

    DZY Loves Topological Sorting Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sho ...

  5. hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]

    传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131 ...

  6. codeforces 446C DZY Loves Fibonacci Numbers 数论+线段树成段更新

    DZY Loves Fibonacci Numbers Time Limit:4000MS     Memory Limit:262144KB     64bit IO Format:%I64d &a ...

  7. Codeforces 446C —— DZY Loves Fibonacci Numbers(线段树)

    题目:DZY Loves Fibonacci Numbers 题意比較简单,不解释了. 尽管官方的题解也是用线段树,但还利用了二次剩余. 可是我没有想到二次剩余,然后写了个感觉非常复杂度的线段树,还是 ...

  8. HDU 5195 - DZY Loves Topological Sorting

    题意: 删去K条边,使拓扑排序后序列字典序最大 分析: 因为我们要求最后的拓扑序列字典序最大,所以一定要贪心地将标号越大的点越早入队.我们定义点i的入度为di. 假设当前还能删去k条边,那么我们一定会 ...

  9. HDU 5195 DZY Loves Topological Sorting 拓扑排序

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5195 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

随机推荐

  1. Mac 动态库加载不上

    OC xcode can't found xxx.dylib 1 targer- build phase :link binary with library添加动态库 注意不要将后边的选项选成opti ...

  2. [leetcode]151. Reverse Words in a String翻转给定字符串中的单词

    Given an input string, reverse the string word by word. Example: Input: "the sky is blue", ...

  3. Data01-数据结构和算法绪论

    Data01-数据结构和算法绪论 一.数据结构和算法绪论 1.1 什么是数据结构? 数据结构是一门研究非数值计算的程序设计问题中的操作对象,以及它们之间的关系和操作等相关问题的学科. 程序设计=数据结 ...

  4. RPM打包原理、示例、详解及备查( 转)

    RPM(Redhat Package Manager)是用于Redhat.CentOS.Fedora等Linux 分发版(distribution)的常见的软件包管理器.因为它允许分发已编译的软件,所 ...

  5. JQuery UI之Autocomplete(2)后端获取数据

    1.Autocomplete获取后台数据 首先引入css和js文件,以及对应的HTML代码如下: <link href="../css/jquery-ui.css" rel= ...

  6. C语言常用关键字及运算符操作

    1.关键字 (1)数据类型 char                          1字节,8bit==256 int long,short unsgined  ,signed      无符号为 ...

  7. c语言使用指针对int数组的求和

    #include <stdio.h> int sump(int *, int *); int main(void) { , , , , }; printf()); ; } int sump ...

  8. 梦殇 chapter one

    梦殇 chapter one 星梦 天空中飘着几片云,喝着小鸟的欢呼声,这一切似乎显得愈加可爱了. 不觉间已经到了2013年,错过的12年,似乎在向我们招手,不知道远方的朋友们,你们还好吗? 是否也会 ...

  9. abp ef codefirst Value cannot be null. Parameter name: connectionString

    错误原因是abp生成的项目是mvc类型的,但在使用时,选择了vue去开发,所以在abp上重新生成了一个vue项目,把原有的mvc项目给删掉了,没有将新生成的vue类型的项目的文件覆盖掉原有的mvc其他 ...

  10. js拷贝指定内容到剪切板

    function copyTextToClipboard(text) { var textArea = document.createElement("textarea"); te ...