#include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
const int mod = 1e9 + 37;
int n, m, s, t;
bool vis[maxn];
vector<pair<int, long long> > a1[maxn], a2[maxn];
long long d1[maxn], d2[maxn], l[maxn], rl[maxn];
struct re {
  int x, y, w;
} e[maxn];
void enter() {
  cin >> n >> m >> s >> t;
  for (int i = (1); i <= (m); ++i) {
    int xx, yy, ww;
    cin >> xx >> yy >> ww;
    e[i].x = xx;
    e[i].y = yy;
    e[i].w = ww;
    a1[xx].push_back(make_pair(yy, ww));
    a2[yy].push_back(make_pair(xx, ww));
  }
}
void dijkstra() {
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      heap;
  for (int i = (1); i <= (n); ++i) {
    vis[i] = 0;
    d1[i] = 1e18;
    d2[i] = 1e18;
  }
  d1[s] = 0;
  d2[t] = 0;
  l[s] = 1;
  rl[t] = 1;
  heap.push(make_pair(0, s));
  while (!heap.empty()) {
    int u = heap.top().second;
    heap.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (int i = (0); i < (a1[u].size()); ++i) {
      int v = a1[u][i].first;
      if (d1[v] == d1[u] + a1[u][i].second) l[v] = (l[v] + l[u]) % mod;
      if (d1[v] > d1[u] + a1[u][i].second) {
        d1[v] = d1[u] + a1[u][i].second;
        l[v] = l[u];
        heap.push(make_pair(d1[v], v));
      }
    }
  }
  for (int i = (1); i <= (n); ++i) vis[i] = 0;
  while (!heap.empty()) heap.pop();
  heap.push(make_pair(0, t));
  while (!heap.empty()) {
    int u = heap.top().second;
    heap.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (int i = (0); i < (a2[u].size()); ++i) {
      int v = a2[u][i].first;
      if (d2[v] == d2[u] + a2[u][i].second) rl[v] = (rl[v] + rl[u]) % mod;
      if (d2[v] > d2[u] + a2[u][i].second) {
        d2[v] = d2[u] + a2[u][i].second;
        rl[v] = rl[u];
        heap.push(make_pair(d2[v], v));
      }
    }
  }
}
void process() {
  dijkstra();
  for (int i = (1); i <= (m); ++i) {
    int x, y, w;
    x = e[i].x;
    y = e[i].y;
    w = e[i].w;
    long long res = d1[x] + d2[y] + w - d1[t];
    if (res == 0) {
      if ((l[x] * rl[y]) % mod == l[t])
        cout << "YES" << '\n';
      else if (w > 1)
        cout << "CAN 1" << '\n';
      else
        cout << "NO" << '\n';
      continue;
    } else if (w - res - 1 >= 1)
      cout << "CAN " << res + 1 << '\n';
    else
      cout << "NO" << '\n';
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  enter();
  process();
  return 0;
}
