1 #include<iostream>
2 #include<cstdio>
3 #include<queue>
4 #include<cstring>
5 const int maxl=2000009;
6 const int maxn=2000000;
7 using namespace std;
8 int n,m,s,t,p;
9 int lin[maxn],cnt=0;
10 struct str
11 {
12 int y;
13 int z;
14 int next;
15 }e[maxl];
16 void insert(int x,int y,int z)
17 {
18 cnt++;
19 e[cnt].next=lin[x];
20 lin[x]=cnt;
21 e[cnt].y=y;
22 e[cnt].z=z;
23 }
24 struct strdis
25 {
26 int x;
27 long long dis;
28 bool operator<(const strdis& a)const{return dis<a.dis;}
29 void set(int xx,int diss){x=xx;dis=diss;}
30 }temp,noww;
31 //bool operator <(const strdis &a,const strdis &b){return a.dis<b.dis;}
32 priority_queue <strdis> q;
33 bool vis[maxn];
34 long long dis[maxn];
35 int main()
36 {
37 while(scanf("%d%d%d%d%d",&n,&m,&s,&p,&t)!=EOF)
38 {
39 memset(lin,0,sizeof(lin));cnt=0;
40 memset(vis,0,sizeof(vis));
41 for(int i=1;i<=m;i++)
42 {
43 int ai,bi,x;
44 scanf("%d%d",&ai,&bi);
45 for(int j=1;j<=bi;j++)
46 {
47 scanf("%d",&x);
48 insert(x,n+i,ai);
49 insert(n+i,x,0);
50 }
51 }
52 temp.set(p,0);
53 q.push(temp);
54 memset(dis,0x3f,sizeof(dis));
55 dis[p]=0;
56 while(!q.empty())
57 {
58 noww=q.top();
59 q.pop();
60 int nn=noww.x;
61 if(vis[nn])continue;
62 vis[nn]=1;
63 for(int i=lin[nn];i;i=e[i].next)
64 {
65 int u=e[i].y;
66 if(dis[u]>dis[nn]+e[i].z)
67 {
68 dis[u]=dis[nn]+e[i].z;
69 temp.set(u,dis[u]);
70 q.push(temp);
71 }
72 }
73 }
74 if((!vis[s])||(!vis[t]))
75 {
76 printf("Poor guy, you don't have enough Money!\n");
77 }
78 else
79 {
80 printf("%lld\n",dis[s]+dis[t]);
81 }
82 }
83
84 return 0;
85 }