3169Layout——poj
来源:互联网 发布:松下a5伺服软件 编辑:程序博客网 时间:2024/05/16 13:06
题意就是给你些不等式
让你求出无解还是有无数解 还是有最小解
okay。。
让你求出无解还是有无数解 还是有最小解
okay。。
裸差分约束
#include<iostream>#include<cstdio>#include<cstring>#include<queue>#define MAXN (1000+10)#define cle(a,b) memset(a,b,sizeof(a))#define loop(i,j) for(int i=1;i<=j;i++)using namespace std;queue<int>q;int inq[MAXN];int dis[MAXN];int vis[MAXN];int n,ml,md;int u;struct edge{int v,w,next;}e[20*MAXN];int cnt;int head[MAXN];void adde(int u,int v,int w){e[++cnt].v=v;e[cnt].w=w;e[cnt].next=head[u];head[u]=cnt;}void readdata(){scanf("%d%d%d",&n,&ml,&md);int a,b,c;cle(head,-1);loop(i,ml){scanf("%d%d%d",&a,&b,&c);adde(b,a,-c);}loop(i,md){scanf("%d%d%d",&a,&b,&c);adde(a,b,c);}}int solve(){cle(dis,-0x3f);/*loop(i,n)adde(0,i,0);*/q.push(n);dis[n]=0;vis[n]=1;inq[n]=1;while(!q.empty()){u=q.front();q.pop();inq[u]=0;for(int i=head[u];i!=-1;i=e[i].next){int v=e[i].v;int w=e[i].w;if(dis[v]<dis[u]+e[i].w){dis[v]=dis[u]+e[i].w;vis[v]++;if(vis[v]>n){printf("-1\n");return 0;}if(!inq[v]){q.push(v);inq[v]=1;}}}}if(dis[1]<=(-0x3f3f3f))return 1;else return 2;}void print(){int bz=solve();if(bz==1)printf("-2\n");else if(bz==2)printf("%d\n",-dis[1]);}int main(){freopen("in.in","r",stdin);//freopen("out.out","w",stdout);readdata();print();}
0 0
- poj 3169——Layout
- 3169Layout——poj
- 刷题——Layout POJ
- 差分约束——Layout ( POJ 3169 )
- POJ 3169 Layout——差分约束
- poj 3169 Layout
- poj 3169 Layout
- poj 3169 Layout
- POJ 3169 Layout
- poj 3169 layout
- POJ 3169 Layout
- poj 3169 Layout
- ACM POJ 3169 (Layout)
- poj 3169 Layout
- POJ-3169 Layout
- poj 3169 Layout
- POJ 3169 Layout
- POJ No.3169 Layout
- Redis配置参数的热修改
- Mat 数据类型保存为二进制文件
- 信号完整性
- C/C++中extern关键字详解
- 1201Intervals——poj
- 3169Layout——poj
- 数据链路层的三个基本问题
- Mat 转成 Vector 类型数据
- noip2008提高组——火柴棒等式
- 菜鸟学习之Android Fragment 开发,快速提升用户体验的方法(二)
- 关于Verilog的可综合性
- 3269混合背包——codevs
- 谈VHDL/Verilog的可综合性以及对初学者的一些建议
- 【C++】统筹全局