The difference question is still quite tangled. Although this question is not shown in a diagram, all the inequalities are given to you, and there are no implicit conditions, just pay attention to <(>) it can be converted to <= (> =), but it remains at the level of the Set template, without a deep understanding of the theoretical significance, and will continue to work hard in the future.
Code:
#include<cstdio>#include<cstring>#include<queue>using namespace std;const int N = 110;struct Edge{int s,e,v,next;}edge[10010];int n,e_num,head[N],vis[N],dist[N],countx[N];queue <int>q;void AddEdge(int a,int b,int c){edge[e_num].s=a; edge[e_num].e=b; edge[e_num].v=c;edge[e_num].next=head[a]; head[a]=e_num++;}void getmap(){int m,a,b,c;char ch[3];scanf("%d",&m);e_num=0;memset(head,-1,sizeof(head));memset(vis,0,sizeof(vis));memset(countx,0,sizeof(countx));while(m--){scanf("%d%d%s%d",&a,&b,ch,&c);if(strcmp(ch,"gt")==0) AddEdge(a+b+1,a,-c-1);else AddEdge(a,a+b+1,c-1);if(!vis[a]){q.push(a); vis[a]=1; countx[a]++;}if(!vis[a+b+1]){q.push(a+b+1); vis[a+b+1]=1; countx[a+b+1]++;}}}int spfa(){while(!q.empty()){int cur=q.front();q.pop();vis[cur]=0;if(countx[cur]>n)return 0;for(int i=head[cur];i!=-1;i=edge[i].next){int u=edge[i].e;if(dist[u]>dist[cur]+edge[i].v){dist[u]=dist[cur]+edge[i].v;if(!vis[u]){q.push(u); vis[u]=1;countx[u]++;}}}}return 1;}void solve(){memset(dist,0,sizeof(dist));int tmp=spfa();if(tmp)puts("lamentable kingdom");else puts("successful conspiracy");}int main(){while(scanf("%d",&n),n){getmap();solve();}return 0;}