#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u, v, nxt, id, w;
} e[200050], rev[200050], aft[200050];
int head[100050], ecnt;
int hrev[100050], rcnt;
int haft[100050], acnt;
void add(int u, int v, int w, int id) {
  rev[++rcnt].v = v;
  rev[rcnt].nxt = hrev[u];
  rev[rcnt].id = id;
  rev[rcnt].w = w;
  hrev[u] = rcnt;
}
void adde(int u, int v, int w, int id) {
  e[++ecnt].v = v;
  e[ecnt].u = u;
  e[ecnt].nxt = head[u];
  e[ecnt].id = id;
  e[ecnt].w = w;
  head[u] = ecnt;
  add(v, u, w, id);
}
void adda(int u, int v, int id) {
  aft[++acnt].v = v;
  aft[acnt].id = id;
  aft[acnt].nxt = haft[u];
  haft[u] = acnt;
}
long long dis[100050], dis2[100050];
int s, t, n, m;
bool vis[100050];
void dij1() {
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      que;
  memset(dis, 0x3f3f3f3f, sizeof(dis));
  memset(vis, 0, sizeof(vis));
  dis[s] = 0;
  que.push(make_pair(0, s));
  while (!que.empty()) {
    int u = que.top().second;
    que.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (int i = head[u]; i; i = e[i].nxt) {
      int v = e[i].v;
      if (dis[v] > dis[u] + e[i].w) {
        dis[v] = dis[u] + e[i].w;
        que.push(make_pair(dis[v], v));
      }
    }
  }
}
void dij2() {
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      que;
  memset(dis2, 0x3f3f3f3f, sizeof(dis2));
  memset(vis, 0, sizeof(vis));
  dis2[t] = 0;
  que.push(make_pair(0, t));
  while (!que.empty()) {
    int u = que.top().second;
    que.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (int i = hrev[u]; i; i = rev[i].nxt) {
      int v = rev[i].v;
      if (dis2[v] > dis2[u] + rev[i].w) {
        dis2[v] = dis2[u] + rev[i].w;
        que.push(make_pair(dis2[v], v));
      }
    }
  }
}
bool is_bridge[100050];
int dfn[100050], low[100050], dcnt;
int fa[100050];
void tarjan(int pos) {
  dfn[pos] = ++dcnt;
  low[pos] = dfn[pos];
  for (int i = haft[pos]; i; i = aft[i].nxt) {
    int v = aft[i].v;
    if (!dfn[v]) {
      fa[v] = aft[i].id;
      tarjan(v);
      low[pos] = min(low[pos], low[v]);
      if (low[v] > dfn[pos]) is_bridge[fa[v]] = 1;
    } else if (fa[pos] != aft[i].id) {
      low[pos] = min(low[pos], dfn[v]);
    }
  }
}
void work_build() {
  dij1();
  dij2();
  long long Min = dis[t];
  for (int i = 1; i <= ecnt; ++i)
    if (dis2[e[i].v] + dis[e[i].u] + e[i].w == Min)
      adda(e[i].u, e[i].v, e[i].id), adda(e[i].v, e[i].u, e[i].id);
  tarjan(s);
  for (int i = 1; i <= ecnt; ++i) {
    long long d = dis[e[i].u] + dis2[e[i].v] + e[i].w;
    if (dis[e[i].u] == dis[0] || dis2[e[i].v] == dis[0]) {
      printf("NO\n");
      continue;
    }
    if (is_bridge[i])
      printf("YES\n");
    else if (d == Min && e[i].w > 1)
      printf("CAN 1\n");
    else if (d > Min) {
      int tmp = d - Min + 1;
      if (e[i].w <= tmp)
        printf("NO\n");
      else
        printf("CAN %d\n", tmp);
    } else
      printf("NO\n");
  }
}
int main() {
  scanf("%d%d%d%d", &n, &m, &s, &t);
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    adde(u, v, w, i);
  }
  work_build();
}
