#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
const double pi = 3.14159265358979;
const int maxn = 1e5 + 5;
const int maxm = 1e7 + 233;
const int mod1 = 1e9 + 7;
const int mod2 = 1e9 + 9;
struct edge {
  int to, nxt;
  long long w;
} edge[maxn << 1];
int tot, head[maxn << 1];
void init() {
  tot = 0;
  memset(head, -1, sizeof head);
}
void addedge(int u, int v, long long w) {
  edge[tot].to = v;
  edge[tot].w = w;
  edge[tot].nxt = head[u];
  head[u] = tot++;
}
struct e {
  int u, v;
  long long w;
} e[maxn];
struct node {
  int v;
  long long w;
  node(){};
  node(int _v, long long _w) : v(_v), w(_w) {}
  const bool operator<(const node &r) const { return w > r.w; }
} tmp;
long long dis[2][maxn];
bool vis[2][maxn];
long long num1[2][maxn];
long long num2[2][maxn];
void dijkstra(int s, int n, int m, bool flag) {
  init();
  int u, v;
  long long w;
  for (int i = 1; i <= m; ++i) {
    u = e[i].u;
    v = e[i].v;
    w = e[i].w;
    if (flag) swap(u, v);
    addedge(u, v, w);
  }
  for (int i = 0; i <= n; ++i) dis[flag][i] = linf;
  for (int i = 0; i <= n; ++i) vis[flag][i] = false;
  for (int i = 0; i <= n; ++i) num1[flag][i] = 0;
  for (int i = 0; i <= n; ++i) num2[flag][i] = 0;
  priority_queue<node> p;
  while (!p.empty()) p.pop();
  dis[flag][s] = 0;
  num1[flag][s] = num2[flag][s] = 1;
  p.push(node(s, 0));
  while (!p.empty()) {
    tmp = p.top();
    p.pop();
    if (vis[flag][tmp.v]) continue;
    vis[flag][tmp.v] = true;
    for (int i = head[tmp.v]; ~i; i = edge[i].nxt) {
      if (vis[flag][edge[i].to]) continue;
      if (dis[flag][edge[i].to] > dis[flag][tmp.v] + edge[i].w) {
        dis[flag][edge[i].to] = dis[flag][tmp.v] + edge[i].w;
        num1[flag][edge[i].to] = num1[flag][tmp.v];
        num2[flag][edge[i].to] = num2[flag][tmp.v];
        p.push(node(edge[i].to, dis[flag][edge[i].to]));
      } else if (dis[flag][edge[i].to] == dis[flag][tmp.v] + edge[i].w) {
        num1[flag][edge[i].to] =
            (num1[flag][edge[i].to] + num1[flag][tmp.v]) % mod1;
        num2[flag][edge[i].to] =
            (num2[flag][edge[i].to] + num2[flag][tmp.v]) % mod2;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  for (int i = 1; i <= m; ++i) cin >> e[i].u >> e[i].v >> e[i].w;
  dijkstra(t, n, m, true);
  dijkstra(s, n, m, false);
  long long mi = dis[0][t];
  for (int i = 1; i <= m; ++i) {
    if (dis[0][e[i].u] + e[i].w + dis[1][e[i].v] == dis[0][t] &&
        (num1[0][e[i].u] * num1[1][e[i].v]) % mod1 == num1[0][t] &&
        (num2[0][e[i].u] * num2[1][e[i].v]) % mod2 == num2[0][t])
      cout << "YES" << '\n';
    else if (dis[0][t] - dis[0][e[i].u] - dis[1][e[i].v] - 1 > 0)
      cout << "CAN "
           << e[i].w - (dis[0][t] - dis[0][e[i].u] - dis[1][e[i].v] - 1)
           << '\n';
    else
      cout << "NO" << '\n';
  }
  return 0;
}
