#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100020;
const long long Inf = 1LL << 60;
struct edge {
  int u, v, w;
} e[Maxn], e2[Maxn];
vector<int> G[Maxn], G2[Maxn];
int n, m, s, t;
long long d1[Maxn], d2[Maxn];
void dij(int st, long long* d, vector<int> G[], edge e[]) {
  for (int i = 1; i <= n; i++) d[i] = i == st ? 0 : Inf;
  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                 greater<pair<long long, int>>>
      q;
  q.push(pair<long long, int>(d[st], st));
  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    for (int id : G[u]) {
      int v = e[id].v, w = e[id].w;
      if (d[v] > d[u] + w) {
        d[v] = d[u] + w;
        q.push(pair<long long, int>(d[v], v));
      }
    }
  }
}
int ee[Maxn << 1];
bool iscut[Maxn << 1];
int bccno[Maxn];
int pre[Maxn], low[Maxn];
int dfs_t;
int ne;
void dfs(int u, int bef) {
  low[u] = pre[u] = ++dfs_t;
  for (int id : G[u]) {
    if (id == (bef ^ 1)) continue;
    int v = ee[id];
    if (pre[v])
      low[u] = min(low[u], pre[v]);
    else {
      dfs(v, id);
      low[u] = min(low[u], low[v]);
      if (low[v] == pre[v]) iscut[id] = iscut[id ^ 1] = 1;
    }
  }
}
void dfs2(int u) {
  for (int id : G[u]) {
    int v = ee[id];
    if (!iscut[id] && !bccno[v]) {
      bccno[v] = bccno[u];
      dfs2(v);
    }
  }
}
int main() {
  scanf("%d%d%d%d", &n, &m, &s, &t);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    e[i] = (edge){u, v, w};
    e2[i] = (edge){v, u, w};
    G[u].push_back(i);
    G2[v].push_back(i);
  }
  dij(s, d1, G, e);
  dij(t, d2, G2, e2);
  for (int i = 1; i <= n; i++) G[i].clear();
  for (int i = 0; i < m; i++) {
    int u = e[i].u, v = e[i].v, w = e[i].w;
    if (d1[u] + d2[v] + w == d1[t]) {
      ee[ne] = v;
      G[u].push_back(ne++);
      ee[ne] = u;
      G[v].push_back(ne++);
    }
  }
  dfs(s, -1);
  for (int i = 1; i <= n; i++)
    if (!bccno[i]) {
      bccno[i] = i;
      dfs2(i);
    }
  for (int i = 0; i < m; i++) {
    int u = e[i].u, v = e[i].v, w = e[i].w;
    if (d1[u] + d2[v] + w == d1[t]) {
      if (bccno[u] == bccno[v]) {
        if (w == 1)
          puts("NO");
        else
          puts("CAN 1");
      } else
        puts("YES");
    } else {
      if (d1[u] + d2[v] + 1 >= d1[t])
        puts("NO");
      else {
        printf("CAN %lld\n", w - (d1[t] - d1[u] - d2[v] - 1));
      }
    }
  }
}
