POJ 3249 Test for Job(拓扑排序)
来源:互联网 发布:对接公众号源码 编辑:程序博客网 时间:2024/05/16 07:53
题意:求从入度为0的点到出度为0的点的路上的权值最大之和。
思路:拓扑排序,注意,孤立点。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <queue>using namespace std;const int N = 100009;const int M = 1000009;const int INF = 0x3f3f3f3f;int n,m;struct LT{ int nex,to;} L[M];int F[N],cnt;void add(int f,int t){ L[cnt].nex = F[f]; L[cnt].to = t; F[f] =cnt++;}int val[N];int in[N];int sum[N];queue<int> que;void init(){ for(int i=1;i<=n;i++) scanf("%d",&val[i]),sum[i]=-INF; int f,t; memset(F,0,sizeof(F)),cnt=1; memset(in,0,sizeof(in)); for(int i=0;i<m;i++) scanf("%d%d",&f,&t),add(f,t),in[t]++;}void solve(){ int ans = -INF; while(!que.empty()) que.pop(); for(int i=1;i<=n;i++) if(in[i]==0){ que.push(i),sum[i]=val[i]; if(F[i]==0) ans=max(ans,sum[i]);///孤立点 } while(!que.empty()) { int e = que.front();que.pop(); for(int i=F[e];i;i=L[i].nex) { int to = L[i].to; sum[to]=max(sum[to],sum[e]+val[to]); in[to]--; if(!in[to]) que.push(to); if(F[to]==0) ans = max(ans,sum[to]); } } printf("%d\n",ans);}int main(){ freopen("in.txt","r",stdin); while(~scanf("%d%d",&n,&m)) { init(); solve(); } return 0;}
- poj 3249 Test for Job (拓扑排序)
- POJ 3249 Test for Job(拓扑排序)
- poj 3249 Test for Job(拓扑排序+DP)
- POJ 3249 Test for Job(拓扑排序+dp)
- POJ 3249-Test for Job(拓扑排序&&DP)
- poj 3249 Test for Job 拓扑排序 dp
- POJ 3249 Test for Job 拓扑图DP
- Test for Job (动态规划 + 拓扑排序)
- Test for Job (动态规划 + 拓扑排序)
- poj3249 Test for Job --- 拓扑排序
- POJ3249 Test for Job(拓扑排序+dp)
- POJ_3249 Test for Job(拓扑)
- POJ 3249 Test For Job
- POJ 3249 Test for Job
- poj 3249 Test for Job
- POJ 3249 Test for Job
- POJ 3249 Test for Job
- poj 3249 Test for Job
- 更多的多线程学心得
- ASP.NET服务器控件
- 千里之行始于足下
- SAX解析XML文档
- android 浏览普通彩信列表核心源码
- POJ 3249 Test for Job(拓扑排序)
- MAC下Myeclipse SVN插件安装
- 远程注入DLL
- openstack+xen,使用glance命令镜像的下载和上传
- 【hdu】 Toy Storage 几何
- uva-729 - The Hamming Distance Problem-全排列
- 线性学习器-----最小二乘法 Rosenblatt感知机 delta法则
- 如何联机调试和发布程序(99$)
- WCF4.0 –- RESTful WCF Services (3) (Raw Stream)