[拓扑序] Educational Codeforces Round 25 825E. Minimal Labels
来源:互联网 发布:淘宝水晶店哪家是真的 编辑:程序博客网 时间:2024/06/04 22:21
题意
戳这里
题解
This problem is usually called “Topological labelling”. Though it’s pretty common problem, we decided that it might be educational to some of participants. —cf官方题解
我好菜啊……
这个要反着贪心,反向建图,从
正着搞是不对的,比如这个例子
4 22 34 1
感性理解一下,正着搞有点只顾眼前利益的感觉,把小数字往前放,没有考虑到对后面的影响是否是好的。
#include<cstdio>#include<algorithm>#include<vector>#include<queue>using namespace std;const int maxn=10000005, maxe=maxn;priority_queue< int > _heap;int n,m,d[maxn],now,a[maxn];int fir[maxn],nxt[maxe],son[maxe],tot;void add(int x,int y){ son[++tot]=y; nxt[tot]=fir[x]; fir[x]=tot;}int main(){ //freopen("E.in","r",stdin); //freopen("E.out","w",stdout); scanf("%d%d",&n,&m); for(int i=1;i<=m;i++){ int x,y; scanf("%d%d",&x,&y); add(y,x); d[x]++; } for(int i=1;i<=n;i++) if(!d[i]) _heap.push(i); now=n; while(!_heap.empty()){ int x=_heap.top(); _heap.pop(); a[x]=now--; for(int j=fir[x];j;j=nxt[j]){ if((--d[son[j]])==0) _heap.push(son[j]); } } for(int i=1;i<=n;i++) printf("%d ",a[i]); return 0;}
阅读全文
0 0
- [拓扑序] Educational Codeforces Round 25 825E. Minimal Labels
- Educational Codeforces Round 25 E. Minimal Labels(拓扑排序)
- Educational Codeforces Round 25E. Minimal Labels(拓扑排序+思维)
- Educational Codeforces Round 25 E. Minimal Labels
- Educational Codeforces Round 25 E. Minimal Labels
- CF-Educational-25 E-Minimal Labels (拓扑排序,字典序)
- codeforces 825 E Minimal Labels
- Codeforces 825E Minimal Labels
- HDU 4857 逃生 && Codeforces 825 E. Minimal Labels 逆向拓扑序+优先队列
- cf 825E Minimal Labels 【拓扑】
- codeforce 825E. Minimal Labels 拓扑排序 贪心思想
- Codeforces 825 F Minimal Labels(反向拓扑排序)
- CodeForces 825E Educational #25 E:拓扑排序+优先队列
- cf Educational Codeforces Round 25 E
- Educational Codeforces Round 19 C. Minimal string
- Educational Codeforces Round 19 C. Minimal string
- Educational Codeforces Round 21E
- Educational Codeforces Round 26 E
- 判断三点顺序(顺时针或者逆时针)(模板)
- poj3461——Oulipo(kmp)
- Spring Scheduled + Redis 实现分布式定时器(一)
- 自定义View系列目录索引
- Redis应用场景
- [拓扑序] Educational Codeforces Round 25 825E. Minimal Labels
- Java中serialVersionUID的作用
- 统计学习方法-朴素贝叶斯法(基于R的实现)
- centos6.9-vsftpd安装配置
- sizeof strlen wcslen tcslen 比较
- Shell编程循环结构中continue和break的用法
- 分组分区和索引分区
- #define 嵌入式习题
- 5.AWK细节操作转载