#include <bits/stdc++.h>
using namespace std;
const int MAXn = 1e5 + 10;
const long long oo = 1e18;
vector<pair<long long, long long> > mat[MAXn], _mat[MAXn], gg[MAXn];
vector<pair<long long, pair<long long, long long> > > edges;
long long diss[MAXn], dise[MAXn], n, m, start, e, mnh[MAXn];
bool flag[MAXn], yes[MAXn];
void dij(int s, bool rev) {
  auto *dis = diss;
  auto *g = mat;
  if (rev) {
    dis = dise;
    g = _mat;
  }
  fill_n(dis, MAXn, oo);
  fill_n(flag, MAXn, 0);
  set<pair<long long, long long> > st;
  st.insert(pair<long long, long long>(0, s));
  dis[s] = 0;
  while (!st.empty()) {
    pair<long long, long long> hp = (*st.begin());
    st.erase(st.begin());
    int v = hp.second;
    if (flag[v]) continue;
    flag[v] = true;
    for (int i = 0; i < g[v].size(); i++) {
      int u = g[v][i].first, wi = g[v][i].second;
      if (dis[u] > dis[v] + wi) {
        dis[u] = dis[v] + wi;
        st.insert(pair<long long, long long>(dis[u], u));
      }
    }
  }
}
void dfs(int v, int hi, int ed) {
  flag[v] = true;
  mnh[v] = hi;
  for (int i = 0; i < gg[v].size(); i++) {
    int u = gg[v][i].first, ind = gg[v][i].second;
    if (!flag[u]) {
      dfs(u, hi + 1, ind);
    }
    if (ind == ed) continue;
    if (mnh[u] > hi) {
      yes[ind] = true;
    }
    mnh[v] = min(mnh[v], mnh[u]);
  }
}
int main() {
  cin >> n >> m >> start >> e;
  start--;
  e--;
  for (int i = 0; i < m; i++) {
    int u, v, l;
    cin >> u >> v >> l;
    u--;
    v--;
    mat[u].push_back(pair<long long, long long>(v, l));
    _mat[v].push_back(pair<long long, long long>(u, l));
    edges.push_back(pair<long long, pair<long long, long long> >(
        l, pair<long long, long long>(u, v)));
  }
  dij(start, 0);
  dij(e, 1);
  for (int i = 0; i < edges.size(); i++) {
    int u = edges[i].second.first, v = edges[i].second.second,
        w = edges[i].first;
    if (diss[u] + w + dise[v] == diss[e]) {
      gg[u].push_back(pair<long long, long long>(v, i));
      gg[v].push_back(pair<long long, long long>(u, i));
    }
  }
  fill_n(flag, MAXn, 0);
  dfs(start, 0, -1);
  for (int i = 0; i < edges.size(); i++) {
    int u = edges[i].second.first, v = edges[i].second.second,
        w = edges[i].first;
    if (yes[i])
      cout << "YES\n";
    else if (w <= w - (diss[e] - (diss[u] + dise[v])) + 1)
      cout << "NO\n";
    else
      cout << "CAN " << w - (diss[e] - (diss[u] + dise[v])) + 1 << '\n';
  }
}
