标签:success reg oid expec ram efi present opera ttl
地址:http://poj.org/problem?id=1364
题目:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 13466 | Accepted: 4793 |
Description
Input
Output
Sample Input
4 2
1 2 gt 0
2 2 lt 2
1 2
1 0 gt 0
1 0 lt 0
0
Sample Output
lamentable kingdom
successful conspiracy
Source
1 #include <cstdio>
2 #include <algorithm>
3 #include <cmath>
4 #include <queue>
5 using namespace std;
6
7 #define MP make_pair
8 #define PB push_back
9 typedef long long LL;
10 typedef pair<int,int> PII;
11 const double eps=1e-8;
12 const double pi=acos(-1.0);
13 const int K=1e6+7;
14 const int mod=1e9+7;
15
16 struct node
17 {
18 int to,v,next;
19 }edge[K];
20 int tot,head[K];
21 void add(int x,int y,int z)
22 {
23 edge[tot].to=y,edge[tot].v=z,edge[tot].next=head[x];
24 head[x]=tot++;
25 }
26 int n,m,vis[K],dis[K],cnt[K];
27 int spfa(int st)
28 {
29 queue<int>q;
30 q.push(st),vis[st]=1,dis[st]=1,cnt[st]=1;
31 while(q.size())
32 {
33 int u=q.front();
34 vis[u]=0;q.pop();
35 for(int i=head[u];~i;i=edge[i].next)
36 {
37 int v=edge[i].to,w=edge[i].v;
38 if(dis[v]<dis[u]+w)
39 {
40 dis[v]=dis[u]+w;
41 if(vis[v]) continue;
42 if(cnt[v]>n) return 1;
43 q.push(v),vis[v]=1,cnt[v]++;
44 }
45 }
46 }
47 return 0;
48 }
49 int main(void)
50 {
51 char ss[20];
52 while(~scanf("%d%d",&n,&m)&&n)
53 {
54 tot=0;
55 for(int i=0;i<=n+1;i++)
56 head[i]=-1,vis[i]=0,dis[i]=0,cnt[i]=0;
57 for(int i=1,u,v,w;i<=m;i++)
58 {
59 scanf("%d%d%s%d",&u,&v,ss,&w);
60 if(ss[0]==‘g‘) add(u-1,u+v,w+1);
61 else add(u+v,u-1,1-w);
62 }
63 for(int i=0;i<=n;i++)
64 add(n+1,i,0);
65 if(spfa(n+1))
66 printf("successful conspiracy\n");
67 else
68 printf("lamentable kingdom\n");
69 }
70 return 0;
71 }
标签:success reg oid expec ram efi present opera ttl
原文地址:http://www.cnblogs.com/weeping/p/6973390.html