#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1e5 + 5;
const int maxm = 1e5 + 5;
int n;
struct Edge {
  int v, w, next;
};
struct Node {
  long long dis;
  int u;
  Node() {}
  Node(long long _dis, int _u) : dis(_dis), u(_u) {}
  bool operator<(const Node& tmp) const { return tmp.dis < dis; }
};
struct Group {
  Edge E[maxm << 1];
  int head[maxn], tol;
  long long dis[maxn];
  int vis[maxn];
  void init() {
    fill(head, head + 1 + n, -1);
    tol = 0;
  }
  void add_edge(int u, int v, int w) {
    E[tol].v = v;
    E[tol].w = w;
    E[tol].next = head[u];
    head[u] = tol++;
  }
  void Spfa(int s) {
    fill(dis, dis + 1 + n, INF);
    fill(vis, vis + 1 + n, 0);
    priority_queue<Node> que;
    que.push(Node(0, s));
    dis[s] = 0;
    while (!que.empty()) {
      int u = que.top().u;
      que.pop();
      if (vis[u]) continue;
      vis[u] = 1;
      for (int i = head[u]; ~i; i = E[i].next) {
        int v = E[i].v;
        if (dis[v] > dis[u] + E[i].w) {
          dis[v] = dis[u] + E[i].w;
          que.push(Node(dis[v], v));
        }
      }
    }
  }
} G, rG;
struct Edge2 {
  int v, id, next;
};
struct Edge3 {
  int u, v, w, flag;
} edge[maxm];
struct Group2 {
  Edge2 E[maxm << 1];
  int head[maxn], tol;
  int dfn[maxn], low[maxn], cnt;
  void init() {
    fill(head, head + n + 1, -1);
    fill(dfn, dfn + n + 1, 0);
    tol = cnt = 0;
  }
  void add_edge(int u, int v, int id) {
    E[tol].v = v;
    E[tol].id = id;
    E[tol].next = head[u];
    head[u] = tol++;
  }
  void Tajan(int u, int pre) {
    dfn[u] = low[u] = ++cnt;
    for (int i = head[u]; ~i; i = E[i].next) {
      if (i == (pre ^ 1)) continue;
      int v = E[i].v;
      if (!dfn[v]) {
        Tajan(v, i);
        low[u] = min(low[u], low[v]);
        if (low[v] > dfn[u]) {
          edge[E[i].id].flag = 1;
        }
      } else {
        low[u] = min(low[u], dfn[v]);
      }
    }
  }
} g;
int main() {
  int m, s, t, u, v, w;
  scanf("%d%d%d%d", &n, &m, &s, &t);
  G.init();
  rG.init();
  g.init();
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    G.add_edge(u, v, w);
    rG.add_edge(v, u, w);
    edge[i].u = u;
    edge[i].v = v;
    edge[i].w = w;
    edge[i].flag = 0;
  }
  G.Spfa(s);
  rG.Spfa(t);
  long long mi = G.dis[t];
  for (int i = 0; i < m; i++) {
    if (G.dis[edge[i].u] + rG.dis[edge[i].v] + edge[i].w == mi) {
      g.add_edge(edge[i].u, edge[i].v, i);
      g.add_edge(edge[i].v, edge[i].u, i);
    }
  }
  g.Tajan(s, -1);
  for (int i = 0; i < m; i++) {
    if (edge[i].flag) {
      puts("YES");
      continue;
    }
    long long d = G.dis[edge[i].u] + rG.dis[edge[i].v] + edge[i].w;
    long long td = d - mi + 1;
    if (edge[i].w > td)
      printf("CAN %I64d\n", td);
    else
      puts("NO");
  }
  return 0;
}
