#include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
vector<pair<long long, int>> g[maxn];
vector<pair<long long, int>> _g[maxn];
int n, m, s, t;
int u[maxn], v[maxn];
long long c[maxn];
void enter() {
  cin >> n >> m >> s >> t;
  for (int i = (0), _b = (m); i < _b; ++i) {
    cin >> u[i] >> v[i] >> c[i];
    g[u[i]].push_back(pair<long long, int>(c[i], v[i]));
    _g[v[i]].push_back(pair<long long, int>(c[i], u[i]));
  }
}
const long long mod = 1000000321;
long long f1[maxn];
long long c1[maxn];
long long c2[maxn];
long long f2[maxn];
bool d[maxn];
const long long oo = 1000000000000123;
void dijkstra1() {
  for (int i = (1), _b = (n + 1); i < _b; ++i) f1[i] = oo;
  f1[s] = 0;
  c1[s] = 1;
  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                 greater<pair<long long, int>>>
      heap;
  heap.push(pair<long long, int>(0, s));
  while (!heap.empty()) {
    pair<long long, int> q = heap.top();
    heap.pop();
    if (!d[q.second]) {
      d[q.second] = true;
      f1[q.second] = q.first;
      for (auto i : g[q.second])
        if (!d[i.second]) {
          if (q.first + i.first < f1[i.second]) {
            f1[i.second] = q.first + i.first;
            c1[i.second] = c1[q.second];
            heap.push(pair<long long, int>(f1[i.second], i.second));
          } else if (q.first + i.first == f1[i.second]) {
            c1[i.second] += c1[q.second];
            c1[i.second] = c1[i.second] % mod;
          }
        }
    }
  }
}
void dijkstra2() {
  for (int i = (1), _b = (n + 1); i < _b; ++i) {
    f2[i] = oo;
    d[i] = false;
  }
  f2[t] = 0;
  c2[t] = 1;
  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                 greater<pair<long long, int>>>
      heap;
  heap.push(pair<long long, int>(0, t));
  while (!heap.empty()) {
    pair<long long, int> q = heap.top();
    heap.pop();
    if (!d[q.second]) {
      d[q.second] = true;
      f2[q.second] = q.first;
      for (auto i : _g[q.second])
        if (!d[i.second]) {
          if (q.first + i.first < f2[i.second]) {
            f2[i.second] = q.first + i.first;
            c2[i.second] = c2[q.second];
            heap.push(pair<long long, int>(f2[i.second], i.second));
          } else if (q.first + i.first == f2[i.second]) {
            c2[i.second] += c2[q.second];
            c2[i.second] = c2[i.second] % mod;
          }
        }
    }
  }
}
long long cnp(long long l, long long r, int i) {
  if (l == r)
    return l;
  else {
    long long mid = ((l + r) / 2) + 1;
    if (f1[u[i]] + f2[v[i]] + mid < f1[t])
      return cnp(mid, r, i);
    else
      return cnp(l, mid - 1, i);
  }
}
void solve() {
  for (int i = (0), _b = (m); i < _b; ++i) {
    if (f1[u[i]] + c[i] + f2[v[i]] == f1[t] &&
        (c1[u[i]] * c2[v[i]]) % mod == c1[t])
      cout << "YES\n";
    else {
      long long ans = cnp(0, c[i], i);
      if (ans == 0)
        cout << "NO\n";
      else
        cout << "CAN " << c[i] - ans << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  enter();
  dijkstra1();
  dijkstra2();
  solve();
}
