#include <bits/stdc++.h>
using namespace std;
int n, m, s, t, e = 0, e2 = 0;
int adj[100010], nxt[100010], from[100010], to[100010], w[100010], in[100010];
int adj2[100010], nxt2[100010], to2[100010], w2[100010];
vector<int> use;
long long dp1[100010] = {0}, dp2[100010] = {0}, sp, longestDis = 0,
          status[100010];
void add(int a, int b, int c, int i) {
  from[e] = a;
  to[e] = b;
  w[e] = c;
  in[e] = i;
  nxt[e] = adj[b];
  adj[b] = e++;
  to2[e2] = b;
  w2[e2] = c;
  nxt2[e2] = adj2[a];
  adj2[a] = e2++;
}
bool ss(int ea, int eb) {
  return dp1[from[ea]] < dp1[from[eb]] ||
         (dp1[from[ea]] == dp1[from[eb]] && dp1[to[ea]] < dp1[to[eb]]);
}
struct comp {
  bool operator()(const pair<int, long long> &a,
                  const pair<int, long long> &b) {
    return a.second > b.second;
  }
};
void Dijkstra() {
  priority_queue<pair<int, long long>, vector<pair<int, long long> >, comp> q;
  for (int i = 0; i < 100010; i++) dp1[i] = dp2[i] = 1LL << 60;
  dp1[s] = 0;
  q.push({s, 0});
  while (!q.empty()) {
    pair<int, long long> t = q.top();
    q.pop();
    if (t.second > dp1[t.first]) continue;
    for (int k = adj2[t.first]; k != -1; k = nxt2[k]) {
      if (dp1[to2[k]] > t.second + w2[k]) {
        dp1[to2[k]] = t.second + w2[k];
        q.push({to2[k], dp1[to2[k]]});
      }
    }
  }
  dp2[t] = 0;
  q.push({t, 0});
  while (!q.empty()) {
    pair<int, long long> tmp = q.top();
    q.pop();
    if (tmp.second > dp2[tmp.first]) continue;
    for (int k = adj[tmp.first]; k != -1; k = nxt[k]) {
      if (dp2[from[k]] > tmp.second + w[k]) {
        dp2[from[k]] = tmp.second + w[k];
        q.push({from[k], dp2[from[k]]});
      }
    }
  }
}
int main() {
  memset(adj, -1, sizeof(adj));
  memset(adj2, -1, sizeof(adj2));
  for (int i = 0; i < 100010; i++) status[i] = 1LL << 60;
  cin >> n >> m >> s >> t;
  for (int i = 0, a, b, c; i < m; i++) {
    cin >> a >> b >> c;
    add(a, b, c, i);
  }
  Dijkstra();
  sp = dp1[t], longestDis = 0;
  for (int i = 0; i < e; i++)
    if (dp1[from[i]] + dp2[to[i]] + w[i] == sp) use.push_back(i);
  sort(use.begin(), use.end(), ss);
  status[in[use[0]]] = 0;
  longestDis = dp1[to[use[0]]];
  for (int i = 1; i < use.size(); i++) {
    if (dp1[from[use[i]]] < longestDis)
      status[in[use[i - 1]]] = status[in[use[i]]] = 1LL << 60;
    else
      status[in[use[i]]] = 0;
    longestDis = max(longestDis, dp1[to[use[i]]]);
  }
  for (int i = 0; i < e; i++) {
    if (status[in[i]] == 1LL << 60) {
      long long chTo = sp - dp1[from[i]] - dp2[to[i]] - 1;
      if (chTo <= 0 || chTo == w[i])
        status[in[i]] = -1;
      else
        status[in[i]] = w[i] - chTo;
    }
  }
  for (int i = 0; i < m; i++)
    if (status[i] == -1)
      cout << "NO" << endl;
    else if (status[i] == 0)
      cout << "YES" << endl;
    else
      cout << "CAN " << status[i] << endl;
  return 0;
}
