#include <cstdio> #include <cstring> #include <cstdlib> using namespace std; const int N=160; const int MAX=20000000; int n,m; struct G { int v,d,nxt; }map[N]; int tt,hd[N]; int q[N],h,t,used[N],vis[N],d[N]; inline int read(void) { int s=0,f=1; char c=getchar(); for (;c<'0'||c>'9';c=getchar()) if (c=='-') f=-1; for (;'0'<=c&&c<='9';c=getchar()) s=s*10+c-'0'; return s*f; } void ins(int u,int v,int d) { map[++tt].v=v; map[tt].d=d; map[tt].nxt=hd[u]; hd[u]=tt; } void build(void) { int x,y,d; char c; tt=0; memset(hd,0,sizeof hd); for (int i=1;i<=m;i++) { scanf("%d%d %ct %d",&x,&y,&c,&d); if (c=='g') ins(x+y,x-1,d+1); else ins(x-1,x+y,1-d); } for (int i=0;i<=n;i++) ins(n+1,i,0); n++; } void spfa(void) { h=t=0; memset(vis,0,sizeof vis); memset(used,0,sizeof used); for (int i=0;i<=n;i++) d[i]=-MAX; d[n]=0,vis[n]=1,used[n]=1,q[t=1]=n; int k; for (;h^t;) { k=q[h=h%(n+1)+1]; for (int r=hd[k];r;r=map[r].nxt) if (d[k]+map[r].d>d[map[r].v]) { d[map[r].v]=d[k]+map[r].d; vis[map[r].v]++; if (vis[map[r].v]==n+1) { printf("successful conspiracy\n"); return; } if (!used[map[r].v]) { used[map[r].v]=1; q[t=t%(n+1)+1]=map[r].v; } } used[k]=0; } printf("lamentable kingdom\n"); } int main(void) { for (int cc=1;cc;cc++) { n=read(); if (!n) break; m=read(); build(); spfa(); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/u013598409/article/details/47132759