1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| #include <bits/stdc++.h> using namespace std; #define FO(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout) #define fo(i,j,k) for(int i=(j),end_i=(k);i<=end_i;i++) #define ff(i,j,k) for(int i=(j),end_i=(k);i< end_i;i++) #define fd(i,j,k) for(int i=(j),end_i=(k);i>=end_i;i--) #define DEBUG(x) cerr<<#x<<"="<<x<<endl #define all(x) (x).begin(),(x).end() #define cle(x) memset(x,0,sizeof(x)) #define lowbit(x) ((x)&-(x)) #define ll long long #define ull unsigned ll #define db double #define lb long db #define pb push_back #define mp make_pair #define fi first #define se second inline int read() { int x=0; char ch=getchar(); bool f=0; for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1; for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+(ch^48); return f?-x:x; } #define CASET fo(___,1,read()) const int N=2010; const int M=200010; const ll inf=1e18; int n,m; namespace Graph{ int ver[M],val[M],ne[M],head[N],tot=1; inline void add(int x,int y,int z) { ver[++tot]=y; val[tot]=z; ne[tot]=head[x]; head[x]=tot; ver[++tot]=x; val[tot]=z; ne[tot]=head[y]; head[y]=tot; } struct node{ int u; ll d; friend inline bool operator<(const node &A,const node &B) { return A.d>B.d; } }; priority_queue<node> q; ll h[N],d[N]; bool vis[N]; inline void get_dis(int s,int &m,int *id) { for(;!q.empty();q.pop()); q.push((node){s,0}); fo(i,1,n) d[i]=inf,vis[i]=0; d[s]=0; for(int u;!q.empty();) { u=q.top().u; q.pop(); if(vis[u]) continue; vis[u]=1; for(int i=head[u],v;i;i=ne[i]) if(d[v=ver[i]]>d[u]+val[i]) { d[v]=d[u]+val[i]; if(!vis[v]) q.push((node){v,d[v]}); } } fo(i,1,n) id[i]=i,h[i]=d[i]; sort(h+1,h+n+1); m=unique(h+1,h+n+1)-h-1; fo(i,1,n) id[i]=lower_bound(h+1,h+m+1,d[i])-h; } } int s,t,p[N]; int ids[N],idt[N],ns,nt; ll sum[N][N],f[2][N][N]; int siz[N][N]; inline int si(int x,int y,int l,int r) { return siz[l][r]-siz[l][y-1]-siz[x-1][r]+siz[x-1][y-1]; } inline ll su(int x,int y,int l,int r) { return sum[l][r]-sum[l][y-1]-sum[x-1][r]+sum[x-1][y-1]; }
int main() { n=read(); m=read(); s=read(); t=read(); fo(i,1,n) p[i]=read(); int x,y,z; fo(i,1,m) x=read(),y=read(),z=read(),Graph::add(x,y,z); Graph::get_dis(s,ns,ids); Graph::get_dis(t,nt,idt); fo(i,1,n) siz[ids[i]][idt[i]]++,sum[ids[i]][idt[i]]+=p[i]; fo(i,1,ns) fo(j,1,nt) siz[i][j]+=siz[i-1][j]+siz[i][j-1]-siz[i-1][j-1], sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]; fd(i,ns,1) fd(j,nt,1) { if(si(i,j,i,nt)) f[0][i][j]=max(f[0][i+1][j],f[1][i+1][j])+su(i,j,i,nt); else f[0][i][j]=f[0][i+1][j]; if(si(i,j,ns,j)) f[1][i][j]=min(f[1][i][j+1],f[0][i][j+1])-su(i,j,ns,j); else f[1][i][j]=f[1][i][j+1]; } if(f[0][1][1]>0) puts("Break a heart"); else if(f[0][1][1]<0) puts("Cry"); else puts("Flowers"); return 0; }
|