LightOJ 1221 - Travel Company(SPFA判负环)
来源:互联网 发布:义乌淘宝培训学校排名 编辑:程序博客网 时间:2024/06/05 20:39
比较简单:
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <iostream>#include <queue>#include <stack>using namespace std;const int M = 9999;const int N = 109;const int INF = 0x3f3f3f3f;struct LT{ int to,nex,val;}L[M];int F[N],cnt;void add(int f,int t,int d){ L[cnt].to = t; L[cnt].nex = F[f]; L[cnt].val = d; F[f] = cnt++;}int n,m,p,dis[N],inque[N],con[N];int que[N*N];void solve(){ memset(dis,0,sizeof(dis)); memset(con,0,sizeof(con)); for(int i=0;i<n;i++) que[i]=i,inque[i] = 1; int fin = 0; int front=0,rear =n; while(rear>front) { int e =que[front++]; con[e]++; if(con[e]>=n) { fin = true; break; } inque[e] = 0; for(int i=F[e];i;i=L[i].nex) { int to =L[i].to; if(dis[to]>dis[e]+L[i].val) { dis[to] = dis[e]+L[i].val; if(!inque[to]) { inque[to] = true; if(con[to]>(n>>1)&&front>0) que[--front]=to; else que[rear++] = to; } } } } if(fin) printf("YES\n"); else printf("NO\n");}int main(){ freopen("in.txt","r",stdin); int cas,T=1; scanf("%d",&cas); while(cas--) { scanf("%d%d%d",&n,&m,&p); memset(F,0,sizeof(F));cnt=1; int a,b,c,d; for(int i=0;i<m;i++) { scanf("%d%d%d%d",&a,&b,&c,&d); add(a,b,d*p-c); } printf("Case %d: ",T++); solve(); } return 0;}
- LightOJ 1221 - Travel Company(SPFA判负环)
- LightOj 1221 - Travel Company(spfa判负环)
- lightoj-1221-Travel Company(spfa找负环)
- LightOJ 1221 Travel Company(贝尔曼最短路判负环)
- LightOJ - 1221 Travel Company(负环)
- lightoj 1074【spfa判负环】
- Software Company LightOJ
- LightOJ 1074 – Extended Traffic 【SPFA判负环】
- SPFA判负环-LightOJ-1074-Extended Traffic
- lightoj 1036 - A Refining Company
- hdu 2433 Travel(spfa)
- PAT 1030 Travel Plan SPFA
- lightoj 1036 - A Refining Company (dp)
- LightOJ - 1180 Software Company(二分+dp)
- LightOJ - 1039 A Toy Company(BFS)
- LightOJ 1036 - A Refining Company(dp)
- LightOJ 1036 - A Refining Company(dp)
- LightOJ 1036 - A Refining Company(DP)
- man bash 6 变量
- 我的第一个Java程序
- 传谷歌微软争夺频率资源欲建设免费Wi-Fi网络
- 只要自己亲手去做,没有成功或失败。
- java在控台体输出0~9
- LightOJ 1221 - Travel Company(SPFA判负环)
- Python数据抓取(抓图片)
- 多线程同步之Mutex(互斥对象)
- Spatialite for Android编译及测试
- IT外企那些事儿
- Google Code项目Git版本控制
- 让我吐槽会
- (vim+ctags+taglist +cscope):(ubuntu 10.10下安装Ctags与TAGLISTS插件)
- 用Intent启动Activity,并在Activity之间传递数据