#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const long long INF = 1e12;
int n, m, S, T, from[N], to[N];
long long d[2][N], w[N];
vector<int> g[2][N], pre[2][N];
bool done[2][N], mark[N], vis[N];
void dij(int x) {
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      Q;
  fill(d[x] + 1, d[x] + 1 + n, INF);
  int SS = x ? T : S;
  d[x][SS] = 0;
  Q.push(make_pair(0, SS));
  while (!Q.empty()) {
    int dist = Q.top().first, u = Q.top().second;
    Q.pop();
    if (done[x][u]) continue;
    done[x][u] = 1;
    for (int i = 0; i < g[x][u].size(); i++) {
      int v = g[x][u][i];
      int r = x ? from[v] : to[v];
      if (d[x][r] > d[x][u] + w[v]) {
        d[x][r] = d[x][u] + w[v];
        pre[x][r].clear();
        pre[x][r].push_back(v);
        Q.push(make_pair(d[x][r], r));
      } else if (d[x][r] == d[x][u] + w[v])
        pre[x][r].push_back(v);
    }
  }
  if (!x) {
    queue<int> q;
    q.push(T);
    vis[T] = 1;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < pre[x][u].size(); i++) {
        int v = pre[x][u][i];
        mark[v] = 1;
        if (!vis[from[v]]) {
          vis[from[v]] = 1;
          q.push(from[v]);
        }
      }
    }
  }
}
int low[N], dfn[N], tt;
vector<int> br[N];
bool ok[N];
void tarjan(int u, int fa) {
  low[u] = dfn[u] = ++tt;
  for (int i = 0; i < br[u].size(); i++) {
    int v = br[u][i], nxt = (u == from[v]) ? to[v] : from[v];
    if (!dfn[nxt]) {
      tarjan(nxt, v);
      low[u] = min(low[u], low[nxt]);
    } else if (v != fa)
      low[u] = min(low[u], dfn[nxt]);
    if (dfn[u] < low[nxt]) ok[v] = 1;
  }
}
void cal_br() {
  for (int i = 1; i <= m; i++) {
    if (mark[i]) br[from[i]].push_back(i), br[to[i]].push_back(i);
  }
  tarjan(S, 0);
}
int main() {
  scanf("%d%d%d%d", &n, &m, &S, &T);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%I64d", &from[i], &to[i], &w[i]);
    g[0][from[i]].push_back(i);
    g[1][to[i]].push_back(i);
  }
  dij(0), dij(1);
  cal_br();
  for (int i = 1; i <= m; i++) {
    if (ok[i]) {
      puts("YES");
      continue;
    }
    long long cost = d[0][T];
    if (d[0][from[i]] + d[1][to[i]] + 1 >= cost) {
      puts("NO");
      continue;
    }
    printf("%s %I64d\n", "CAN",
           w[i] - (cost - 1 - d[0][from[i]] - d[1][to[i]]));
  }
  return 0;
}
