#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int maxn = 2e5 + 100;
int n, m;
struct Edge {
  int u, v, w, next;
  Edge() {}
  Edge(int a, int b, int N, long long W) {
    u = a;
    v = b;
    next = N;
    w = W;
  }
};
bool inq[maxn];
struct Graph {
  Edge edge[maxn];
  int ednum, head[maxn];
  long long dis[maxn];
  void init() {
    memset(head, -1, sizeof(head));
    ednum = 0;
  }
  const long long inf = 1e18 + 10;
  priority_queue<pair<int, long long>, vector<pair<int, long long> >,
                 greater<pair<int, long long> > >
      q;
  void dij(int a) {
    int i, v, now;
    for (i = 0; i <= n; i++) dis[i] = inf;
    dis[a] = 0;
    q.push(make_pair(0, a));
    while (!q.empty()) {
      now = q.top().second;
      q.pop();
      for (i = head[now]; i != -1; i = edge[i].next) {
        v = edge[i].v;
        if (dis[v] > dis[now] + edge[i].w) {
          dis[v] = dis[now] + edge[i].w;
          q.push(make_pair(dis[v], v));
        }
      }
    }
  }
} g1, g2;
struct Tree {
  Edge edge[maxn];
  int head[maxn], ednum;
  void init() {
    memset(head, -1, sizeof(head));
    ednum = 0;
  }
} tr;
bool is[maxn], inst[maxn];
int stk[maxn], stn, low[maxn], dfn[maxn], idx;
void tarjan(int u, int pre) {
  low[u] = dfn[u] = ++idx;
  inst[u] = true;
  stk[stn++] = u;
  int i, v;
  for (i = tr.head[u]; i != -1; i = tr.edge[i].next) {
    if (i == (pre ^ 1)) continue;
    v = tr.edge[i].v;
    if (!inst[v]) {
      tarjan(v, i);
      low[u] = min(low[v], low[u]);
    } else
      low[u] = min(dfn[v], low[u]);
  }
  if (low[u] == dfn[u]) {
    while (stk[stn - 1] != u) {
      inst[stk[stn - 1]] = false;
      stn--;
    }
    inst[stk[stn - 1]] = false;
    stn--;
    is[pre] = is[pre ^ 1] = true;
  }
}
int main() {
  int s, t, i;
  int a, b;
  stn = idx = 0;
  tr.init();
  g1.init();
  g2.init();
  long long w, ds;
  scanf("%d %d %d %d", &n, &m, &s, &t);
  for (i = 0; i < m; i++) {
    scanf("%d %d %I64d", &a, &b, &w);
    g1.edge[g1.ednum] = Edge(a, b, g1.head[a], w);
    g1.head[a] = g1.ednum;
    g1.ednum += 2;
    g2.edge[g2.ednum] = Edge(b, a, g2.head[b], w);
    g2.head[b] = g2.ednum++;
  }
  g1.dij(s);
  ds = g1.dis[t];
  g2.dij(t);
  for (i = 0; i < g1.ednum; i += 2) {
    a = g1.edge[i].u;
    b = g1.edge[i].v;
    if (g1.dis[a] + g1.edge[i].w + g2.dis[b] == ds) {
      tr.edge[i] = Edge(a, b, tr.head[a], w);
      tr.head[a] = i;
      tr.edge[i ^ 1] = Edge(b, a, tr.head[b], w);
      tr.head[b] = i ^ 1;
    }
  }
  tarjan(s, -1);
  for (i = 0; i < g1.ednum; i += 2)
    if (is[i])
      printf("YES\n");
    else {
      long long tmp =
          g1.dis[g1.edge[i].u] + g2.dis[g1.edge[i].v] + g1.edge[i].w - ds;
      if (g1.edge[i].w > tmp + 1)
        printf("CAN %I64d\n", tmp + 1);
      else
        printf("NO\n");
    }
  return 0;
}
