#include <bits/stdc++.h>
using namespace std;
const long long int inf = 2e18;
vector<pair<pair<int, int>, long long int> > e;
vector<pair<int, long long int> > g[200005], ng[200005], rg[200005];
long long int s[200005], d[200005];
int vs[200005];
int ans[100005];
int in[200005], p[200005], t = 0, m[100005];
int dfs(int u) {
  vs[u] = 1;
  in[u] = t++;
  int dbe = in[u];
  for (int i = 0; i < (int)(ng[u].size()); i++) {
    int w = ng[u][i].first, index = ng[u][i].second;
    if (!vs[w]) {
      ans[index] = 1;
      m[index] = 1;
      p[w] = u;
      int be = dfs(w);
      if (be == in[w]) {
        ;
        ans[index] = 2;
      } else
        dbe = min(dbe, be);
    } else if (!m[index]) {
      ans[index] = 1;
      dbe = min(dbe, in[w]);
    }
  }
  return dbe;
}
int main() {
  int n, m, start, finish, a, b;
  long long int c;
  scanf("%d", &n);
  scanf("%d", &m);
  scanf("%d", &start);
  scanf("%d", &finish);
  for (int i = 0; i < m; i++) {
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%lld", &c);
    g[a].push_back(make_pair(b, c));
    rg[b].push_back(make_pair(a, c));
    e.push_back(make_pair(make_pair(a, b), c));
  }
  set<pair<long long int, int> > q;
  for (int i = 1; i <= n; i++) {
    s[i] = inf;
    vs[i] = 0;
  }
  s[start] = 0;
  q.insert(make_pair(s[start], start));
  while (!q.empty()) {
    int u = (*q.begin()).second;
    q.erase(q.begin());
    vs[u] = 1;
    for (int i = 0; i < (int)(g[u].size()); i++) {
      int w = g[u][i].first;
      long long int edge = g[u][i].second;
      if (s[u] + edge < s[w]) {
        s[w] = s[u] + edge;
        q.insert(make_pair(s[w], w));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    d[i] = inf;
    vs[i] = 0;
  }
  d[finish] = 0;
  q.insert(make_pair(d[finish], finish));
  while (!q.empty()) {
    int u = (*q.begin()).second;
    q.erase(q.begin());
    vs[u] = 1;
    for (int i = 0; i < (int)(rg[u].size()); i++) {
      int w = rg[u][i].first;
      long long int edge = rg[u][i].second;
      if (d[u] + edge < d[w]) {
        d[w] = d[u] + edge;
        q.insert(make_pair(d[w], w));
      }
    }
  }
  for (int i = 0; i < (int)(e.size()); i++) {
    a = e[i].first.first, b = e[i].first.second, c = e[i].second;
    if (s[a] + c + d[b] == s[finish]) {
      ng[a].push_back(make_pair(b, i));
      ng[b].push_back(make_pair(a, i));
      ;
    }
  }
  memset(vs, 0, sizeof(vs));
  dfs(start);
  for (int i = 0; i < (int)(e.size()); i++) {
    if (ans[i] == 2)
      cout << "YES" << endl;
    else {
      a = e[i].first.first, b = e[i].first.second, c = e[i].second;
      if (s[a] == inf || d[b] == inf) {
        cout << "NO" << endl;
        continue;
      }
      int nw = s[finish] - s[a] - d[b] - 1;
      ;
      if (nw > 0)
        cout << "CAN " << c - nw << endl;
      else
        cout << "NO" << endl;
    }
  }
  return 0;
}
