#include <bits/stdc++.h>
using namespace std;
const int mod1 = 1e9 + 7, mod2 = 998244353;
pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {
  return make_pair((a.first + b.first) % mod1, (a.second + b.second) % mod2);
}
pair<int, int> operator*(const pair<int, int> &a, const pair<int, int> &b) {
  return make_pair(1ll * a.first * b.first % mod1,
                   1ll * a.second * b.second % mod2);
}
struct node {
  int e;
  long long w;
  friend bool operator<(const node &a, const node &b) { return a.w > b.w; }
};
struct edge {
  int u, v;
  long long w;
} a[100005];
int n, m, s, t;
pair<int, int> dp[2][100005];
long long dis[2][100005];
vector<node> g[2][100005];
priority_queue<node> q;
void dij(int s, long long *dis, pair<int, int> *dp, vector<node> *g) {
  q.push((node){s, 0});
  dp[s] = make_pair(1, 1);
  dis[s] = 0;
  while (!q.empty()) {
    node t = q.top();
    q.pop();
    for (int i = 0; i < g[t.e].size(); i++) {
      int v = g[t.e][i].e;
      if (t.w + g[t.e][i].w == dis[v]) dp[v] = dp[v] + dp[t.e];
      if (t.w + g[t.e][i].w < dis[v]) {
        dis[v] = t.w + g[t.e][i].w;
        dp[v] = dp[t.e];
        q.push((node){v, t.w + g[t.e][i].w});
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  memset(dis, 0x3f, sizeof(dis));
  cin >> n >> m >> s >> t;
  for (int i = 1, u, v; i <= m; i++) {
    long long w;
    cin >> u >> v >> w;
    a[i].u = u;
    a[i].v = v;
    a[i].w = w;
    g[0][u].push_back((node){v, w});
    g[1][v].push_back((node){u, w});
  }
  dij(s, dis[0], dp[0], g[0]);
  dij(t, dis[1], dp[1], g[1]);
  for (int i = 1; i <= m; i++) {
    if (dp[0][a[i].u] * dp[1][a[i].v] == dp[0][t] &&
        dis[0][a[i].u] + a[i].w + dis[1][a[i].v] == dis[0][t])
      cout << "YES\n";
    else if (dis[0][t] - 1 - dis[0][a[i].u] - dis[1][a[i].v] <= 0)
      cout << "NO\n";
    else
      cout << "CAN "
           << a[i].w - (dis[0][t] - 1 - dis[0][a[i].u] - dis[1][a[i].v])
           << '\n';
  }
  return 0;
}
