这题主要n也取得到。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int maxn=100+10;
struct edge{
int from,to,dist;
};
struct BellmanFord{
int n,m;
vector<edge> edges;
vector<int> G[maxn];
bool inq[maxn];
double d[maxn];
int p[maxn];
int cnt[maxn];
void init(int n){
this->n=n;
for(int i=0;i<=n;i++) G[i].clear();
edges.clear();
}
void addedge(int from,int to,int dist){
edges.push_back(edge{from,to,dist});
m=(int)edges.size();
G[from].push_back(m-1);
}
bool negativeCycle(){
queue<int> q;
memset(inq,0,sizeof(inq));
memset(cnt,0,sizeof(cnt));
for(int i=0;i<=n;i++) {d[i]=0;inq[i]=true;q.push(i);}
while(!q.empty()){
int u=q.front();q.pop();
inq[u]=false;
for(int i=0;i<G[u].size();i++){
edge &e=edges[G[u][i]];
if(d[e.to]>d[e.from]+e.dist){
d[e.to]=d[u]+e.dist;
p[e.to]=G[u][i];
if(!inq[e.to]) {q.push(e.to);inq[e.to]=true;if(++cnt[e.to]>n+1) return true;}
}
}
}
return false;
}
};
int n,m;
BellmanFord solver;
int main()
{
while(scanf("%d",&n)&&n)
{
solver.init(n);
scanf("%d",&m);
int u,v,dist;
char ch[3];
for(int i=0;i<m;i++){
int a,b;
scanf("%d%d%s%d",&a,&b,ch,&dist);
u=a+b;v=a-1;
if(ch[0]=='g') solver.addedge(u,v,-dist-1);
else solver.addedge(v,u,dist-1);
}
if(!solver.negativeCycle()) printf("lamentable kingdom\n");
else printf("successful conspiracy\n");
}
return 0;
}