#include <bits/stdc++.h>
using namespace std;
long long mindis = 1LL * 0x7fffffff * 0x7fffffff;
struct fuck {
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      q;
  int pre[2010000], now[2010000], tot, son[2010000], val[2010000];
  void init() {
    memset(now, 0, sizeof(now));
    tot = 0;
  }
  void con(int a, int b, int c) {
    pre[++tot] = now[a];
    now[a] = tot;
    son[tot] = b;
    val[tot] = c;
  }
  long long dis[2010000];
  void dij(int st, int ed) {
    memset(dis, 63, sizeof(dis));
    dis[st] = 0;
    q.push(make_pair(0, st));
    do {
      pair<long long, int> x = q.top();
      q.pop();
      for (int p = now[x.second]; p; p = pre[p])
        if (dis[son[p]] > dis[x.second] + val[p]) {
          dis[son[p]] = dis[x.second] + val[p];
          q.push(make_pair(dis[son[p]], son[p]));
        }
    } while (!q.empty());
    mindis = min(mindis, dis[ed]);
  }
} z, f;
int dfn[2010000], num, low[2010000], fa[2010000];
bool qiao[2010000], vis[2010000];
int a[2010000], b[2010000], c[2010000], n, m, s, t;
int pre[2010000], son[2010000], now[2010000], tot, val[2010000], no[2010000];
void con(int a, int b, int c, int d) {
  pre[++tot] = now[a];
  now[a] = tot;
  son[tot] = b;
  val[tot] = c;
  no[tot] = d;
}
void tarjan(int x, int father) {
  vis[x] = 1;
  dfn[x] = low[x] = ++num;
  for (int p = now[x]; p; p = pre[p])
    if (!vis[son[p]]) {
      fa[son[p]] = no[p];
      tarjan(son[p], x);
      low[x] = min(low[x], low[son[p]]);
    } else if (fa[x] != no[p])
      low[x] = min(dfn[son[p]], low[x]);
  if (x != s && fa[x] && low[x] == dfn[x]) {
    qiao[fa[x]] = true;
    if (n == 50) printf("edge:%d %d\n", father, x);
  }
}
int main() {
  scanf("%d%d%d%d", &n, &m, &s, &t);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
    z.con(a[i], b[i], c[i]);
    f.con(b[i], a[i], c[i]);
  }
  z.dij(s, t);
  f.dij(t, s);
  for (int i = 1; i <= m; i++) {
    if (z.dis[a[i]] + f.dis[b[i]] + c[i] == mindis) {
      con(a[i], b[i], c[i], i);
      con(b[i], a[i], c[i], i);
    }
  }
  tarjan(s, s);
  for (int i = 1; i <= m; i++) {
    if (qiao[i])
      puts("YES");
    else if (z.dis[a[i]] + f.dis[b[i]] + c[i] == mindis && c[i] > 1)
      puts("CAN 1");
    else if (z.dis[a[i]] + f.dis[b[i]] < mindis &&
             -z.dis[a[i]] - f.dis[b[i]] + mindis - 1 > 0) {
      printf("CAN %I64d\n", z.dis[a[i]] + f.dis[b[i]] + c[i] - mindis + 1);
    } else
      puts("NO");
  }
  return 0;
}
