洛谷 1113 杂务 拓扑排序(裸)
来源:互联网 发布:电脑自动打电话软件 编辑:程序博客网 时间:2024/05/16 12:56
题目:
https://www.luogu.org/problem/show?pid=1113
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>using namespace std;const int MAXN=30001;int tot,fst[MAXN],nxt[MAXN],dis[MAXN],n,ru[MAXN],lu[MAXN],vis[MAXN];struct hh{ int from,to;}ma[MAXN<<1];queue<int>q;void build(int f,int t){ tot++; ma[tot]=(hh){f,t}; nxt[tot]=fst[f]; fst[f]=tot; return;}void bfs(){ while(!q.empty()) { int x=q.front(); q.pop(); for(int i=fst[x];i;i=nxt[i]) { int v=ma[i].to; ru[v]--; lu[v]=max(lu[v],lu[x]+dis[v]); if(!ru[v]) q.push(v); } } return;}void solve(){ int x,y,z,ans=0; cin>>n; for(int i=1;i<=n;i++) { scanf("%d%d",&x,&y); dis[x]=y; while(~scanf("%d",&y)) { if(y==0) break; build(y,x),ru[x]++; } } for(int i=1;i<=n;i++) if(!ru[i]) q.push(i),lu[i]=dis[i]; bfs(); for(int i=1;i<=n;i++) ans=max(ans,lu[i]); cout<<ans;}int main(){ solve(); return 0;}
阅读全文
1 0
- 洛谷 1113 杂务 拓扑排序(裸)
- 洛谷P1113 杂务(拓扑排序)
- 【题解】洛谷1113 杂务
- 杂务 洛谷1113 spfa最长路
- 洛谷 P1113 杂务
- 洛谷 P1113 杂务
- 洛谷 P1113 杂务
- 洛谷 [P1113] 杂务
- 杂物_洛谷1113_拓扑排序
- 拓扑排序 (java)
- 拓扑排序(转)
- 拓扑排序(图论)
- 拓扑排序(谢庆皇)
- HDU3342(拓扑排序)
- hdu1285(拓扑排序)
- 拓扑排序 (java)
- hdu1811(拓扑排序)
- poi(拓扑排序)
- 属性和字段的区别
- 9月20日总结
- Java中的对象和引用
- 如何快速解决TeXstudio提示的错误:did you pass the "backend=biber" option to BibLaTeX?
- tf.multinomial()函数的理解
- 洛谷 1113 杂务 拓扑排序(裸)
- Linux基础知识
- 第三周 项目2
- Coroutines in C(by Simon Tatham)
- Python List使用的简单心得
- 第三周 项目一 顺序表的基本运算
- base64的C++实现
- p2469,[sdoi2010]星际竞速
- 小结