#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
struct Dijkstra {
  struct node {
    long long d;
    int u;
    bool operator<(const node& b) const { return d > b.d; }
    node() {}
    node(long long _d, int _u) : d(_d), u(_u) {}
  };
  struct Edge {
    int from, to, id;
    long long dist;
    Edge() {}
    Edge(int u, int v, long long w) : from(u), to(v), dist(w) {}
  };
  int n, m;
  vector<Edge> edges;
  vector<int> G[maxn];
  bool done[maxn];
  long long d[maxn];
  int p[maxn];
  void init(int n) {
    this->n = n;
    for (int i = 0; i <= n; i++) G[i].clear();
    edges.clear();
  }
  void addEdge(int from, int to, long long dist) {
    edges.push_back(Edge(from, to, dist));
    m = edges.size();
    G[from].push_back(m - 1);
  }
  void dijkstra(int s) {
    priority_queue<node> Q;
    for (int i = 0; i <= n; i++) d[i] = (1LL << 61);
    d[s] = 0;
    memset(done, 0, sizeof(done));
    Q.push(node(0, s));
    while (!Q.empty()) {
      node x = Q.top();
      Q.pop();
      int u = x.u;
      if (done[u]) continue;
      done[u] = true;
      for (int i = 0; i < G[u].size(); i++) {
        Edge& e = edges[G[u][i]];
        if (d[e.to] > d[u] + e.dist) {
          d[e.to] = d[u] + e.dist;
          p[e.to] = G[u][i];
          Q.push(node(d[e.to], e.to));
        }
      }
    }
  }
} S, T;
int dfn[maxn];
int dfs_clock;
int low[maxn];
struct Edge {
  int u, v, w, id;
  Edge(int a = 0, int b = 0, int w = 0, int c = 0) : u(a), v(b), w(w), id(c) {}
} e[2 * maxn];
vector<Edge> G[maxn];
bool isbridge[2 * maxn];
int dfs(int u, int la) {
  int lowu = dfn[u] = ++dfs_clock;
  int child = 0;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i].v;
    if (!dfn[v]) {
      int lowv = dfs(v, G[u][i].id);
      lowu = min(lowu, lowv);
      if (lowv > dfn[u]) {
        isbridge[G[u][i].id] = 1;
      }
    } else if (dfn[v] < dfn[u] && G[u][i].id != la) {
      lowu = min(lowu, dfn[v]);
    }
  }
  low[u] = lowu;
  return lowu;
}
int ison[2 * maxn];
int can[2 * maxn];
int main() {
  int n, m, s, t, k;
  scanf("%d%d%d%d", &n, &m, &s, &t);
  S.init(n + 1);
  T.init(n + 1);
  int u, v, w;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    e[i] = Edge(u, v, w, i);
    S.addEdge(u, v, w);
    T.addEdge(v, u, w);
  }
  S.dijkstra(s);
  T.dijkstra(t);
  long long ddd = S.d[t];
  long long delta;
  if (S.d[t] == (1LL << 61)) {
    for (int i = 1; i <= m; i++) printf("NO\n");
  } else {
    for (int i = 1; i <= m; i++) {
      u = e[i].u;
      v = e[i].v;
      w = e[i].w;
      if (S.d[u] + w == S.d[v] && T.d[v] + w == T.d[u]) {
        G[u].push_back(Edge(u, v, w, i));
        G[v].push_back(Edge(v, u, w, i));
        ison[i] = 1;
      }
    }
    dfs(s, -1);
    for (int i = 1; i <= m; i++) {
      if (isbridge[i]) {
        printf("YES\n");
      } else {
        delta = S.d[e[i].u] + T.d[e[i].v] + e[i].w - ddd + 1;
        if (delta < e[i].w)
          printf("CAN %I64d\n", delta);
        else
          printf("NO\n");
      }
    }
  }
  return 0;
}
