#include<stdio.h> #include<iostream> #include<stack> #include<string.h> using namespace std; #define inf 999999999 #define N 300 struct node { int u,v,w,next; }bian[N*10]; int yong,n,head[N]; void addedge(int u,int v,int w) { bian[yong].v=v; bian[yong].w=w; bian[yong].next=head[u]; head[u]=yong++; } int bellman() { int dis[N],visit[N],count[N]; int cur,i; for(i=0;i<=n;i++) addedge(n+1,i,0); for(i=0;i<=n+1;i++) dis[i]=inf; memset(visit,0,sizeof(visit)); memset(count,0,sizeof(count)); stack<int>q; dis[n+1]=0; q.push(n+1); while(!q.empty()) { cur=q.top(); q.pop(); visit[cur]=0; for(i=head[cur];i!=-1;i=bian[i].next) if(dis[bian[i].v]>dis[cur]+bian[i].w) { dis[bian[i].v]=dis[cur]+bian[i].w; if(!visit[bian[i].v]) { visit[bian[i].v]=1; if(++count[bian[i].v]>n) return 0; q.push(bian[i].v); } } } return 1; } int main() { int i,j,k,m; char s[30]; while(scanf("%d",&n),n) { scanf("%d",&m); yong=0; memset(head,-1,sizeof(head)); while(m--) { scanf("%d%d%s%d",&i,&j,s,&k); if(s[0]=='g') addedge(i+j,i-1,-k-1); if(s[0]=='l') addedge(i-1,i+j,k-1); } if(bellman()) printf("lamentable kingdom\n"); else printf("successful conspiracy\n"); } return 0; }
poj 1364 查分约束
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
下一篇:poj 3159 差分约束
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
约束训练
约束训练
2d ide 加载 -
POJ - 1364 King (差分约束系统)
题目大意:给出N个
Max #define i++ -
POJ - 1364 巧妙构图的差分约束
题目的意思抽象出来就是有一个数列...a1,a
c i++ 差分约束 ios -
【POJ - 1364】King(差分约束判无解)
题干:
#include ide #define -
POJ 1364 King ( 差分约束 )
KingTime Limit:1000MSMemory Limit:10000KTotal Submissions:8492Accepted:3203DescriptionOnce, in one kingdom, there was a queen and that queen was expecting a baby. The queen prayed: ``If my child was a son and if only he was a sound king.'' After nine months her child was born, and indeed, sh
acm/icpc POJ ide #include i++ 差分约束