栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2770 Burn the Linked Camp

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2770 Burn the Linked Camp

#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#define LL long longusing namespace std;const int N = 3000;struct edge{ int u,v,w,next;}e[N * 200];int head[N],tot,times[N],n,m;LL dis[N];bool inq[N];LL spfa(int source){ queue<int> q; memset(times,0,sizeof(times)); memset(dis,0xc0,sizeof(dis)); memset(inq,false,sizeof(inq)); q.push(source); inq[source] = true , dis[source] = 0; while(! q.empty()){ int u = q.front();q.pop(); // printf("u:%d dis:%I64d times:%dn",u,dis[u],times[u] + 1); if(++ times[u] > n) return -1; for(int i = head[u];i != -1;i = e[i].next){ int v = e[i].v; if(dis[v] < dis[u] + e[i].w){ dis[v] = dis[u] + e[i].w; if(! inq[v]) inq[v] = true , q.push(v); } } inq[u] = false; } return dis[n];}void add_edge(int u,int v,int w){ e[tot].u = u , e[tot].v = v , e[tot].w = w; e[tot].next = head[u] , head[u] = tot ++;}int main(){ while(scanf("%d%d",&n,&m) != EOF){ memset(head,-1,sizeof(head)); tot = 0; for(int i = 1;i <= n;i ++){ int cap; scanf("%d",∩); add_edge(i - 1,i,0); add_edge(i,i - 1,-cap); } for(int i = 1;i <= n;i ++) add_edge(0,i,0); for(int i = 1;i <= m;i ++){ int u,v,w; scanf("%d%d%d",&u,&v,&w); add_edge(u - 1,v,w); } LL ans = spfa(0); if(ans == -1) puts("Bad Estimations"); else printf("%lldn",ans); } return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/374287.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号