#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x;
  scanf("%lld", &x);
  return x;
}
const long long _N = 1e5 + 100;
const long long _M = 2e5 + 100;
namespace E0 {
long long head[_N];
struct edges {
  long long node;
  long long w;
  long long nxt;
} edge[_M];
long long tot = 0;
void add(long long u, long long v, long long w) {
  tot++;
  edge[tot].node = v;
  edge[tot].w = w;
  edge[tot].nxt = head[u];
  head[u] = tot;
}
long long dis[_N];
bool vis[_N];
long long cnt[_N];
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    Q;
void dijkstra(long long s) {
  memset(dis, 0x3f, sizeof(dis));
  memset(cnt, 0, sizeof(cnt));
  dis[s] = 0;
  cnt[s] = 1;
  Q.push(make_pair((dis[s]), (s)));
  while (!Q.empty()) {
    long long now = Q.top().second;
    Q.pop();
    if (vis[now]) continue;
    vis[now] = 1;
    for (long long i = head[now]; i; i = edge[i].nxt) {
      long long ex = edge[i].node;
      if (dis[now] + edge[i].w < dis[ex]) {
        dis[ex] = dis[now] + edge[i].w;
        cnt[ex] = cnt[now];
        Q.push(make_pair((dis[ex]), (ex)));
      } else if (dis[now] + edge[i].w == dis[ex])
        cnt[ex] = (cnt[ex] + cnt[now]) % 998244353LL;
    }
  }
}
}  // namespace E0
namespace E1 {
long long head[_N];
struct edges {
  long long node;
  long long w;
  long long nxt;
} edge[_M];
long long tot = 0;
void add(long long u, long long v, long long w) {
  tot++;
  edge[tot].node = v;
  edge[tot].w = w;
  edge[tot].nxt = head[u];
  head[u] = tot;
}
long long dis[_N];
bool vis[_N];
long long cnt[_N];
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    Q;
void dijkstra(long long s) {
  memset(dis, 0x3f, sizeof(dis));
  memset(cnt, 0, sizeof(cnt));
  dis[s] = 0;
  cnt[s] = 1;
  Q.push(make_pair((dis[s]), (s)));
  while (!Q.empty()) {
    long long now = Q.top().second;
    Q.pop();
    if (vis[now]) continue;
    vis[now] = 1;
    for (long long i = head[now]; i; i = edge[i].nxt) {
      long long ex = edge[i].node;
      if (dis[now] + edge[i].w < dis[ex]) {
        dis[ex] = dis[now] + edge[i].w;
        cnt[ex] = cnt[now];
        Q.push(make_pair((dis[ex]), (ex)));
      } else if (dis[now] + edge[i].w == dis[ex])
        cnt[ex] = (cnt[ex] + cnt[now]) % 998244353LL;
    }
  }
}
}  // namespace E1
struct edges {
  long long u, v, w;
  edges() {}
  edges(long long a, long long b, long long c) {
    u = a;
    v = b;
    w = c;
  }
};
vector<edges> E;
signed main() {
  long long n = read(), m = read(), s = read(), t = read();
  for (long long i = 1; i <= m; i++) {
    long long u = read(), v = read(), w = read();
    E0::add(u, v, w);
    E1::add(v, u, w);
    E.push_back(edges(u, v, w));
  }
  E0::dijkstra(s);
  E1::dijkstra(t);
  long long MINDIS = E0::dis[t];
  long long PATHS = E0::cnt[t];
  cerr << MINDIS << " " << PATHS << endl;
  for (long long i = 0; i < E.size(); i++) {
    edges now = E[i];
    if (now.w + E0::dis[now.u] + E1::dis[now.v] == MINDIS) {
      if ((E0::cnt[now.u] * E1::cnt[now.v]) % 998244353LL ==
          PATHS % 998244353LL)
        puts("YES");
      else
        puts(now.w <= 1 ? "NO" : "CAN 1");
    } else {
      long long nowDis = E0::dis[now.u] + E1::dis[now.v];
      if ((nowDis + now.w) - MINDIS + 1 >= now.w)
        puts("NO");
      else
        printf("CAN %lld\n", (nowDis + now.w) - MINDIS + 1);
    }
  }
  return 0;
}
