#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const long long INF = 1e14 + 333;
struct edge {
  int v, u;
  long long l, r, w;
};
pair<long long, int> drpmax[N][3];
int n, m, s, t;
long long A[N], B[N], Rs[N];
bool forced[N], mark[N];
vector<pair<int, int> > g[N], gb[N];
edge e[N];
void dijkstra(int, long long[], vector<pair<int, int> >[]);
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> s >> t;
  s--;
  t--;
  for (int i = 0; i < m; i++) {
    cin >> e[i].v >> e[i].u >> e[i].w;
    e[i].v--;
    e[i].u--;
    g[e[i].v].push_back({e[i].u, e[i].w});
    gb[e[i].u].push_back({e[i].v, e[i].w});
  }
  dijkstra(s, A, g);
  dijkstra(t, B, gb);
  long long dst = A[t];
  for (int i = 0; i < m; i++) {
    e[i].l = A[e[i].v];
    e[i].r = A[e[i].u];
  }
  vector<int> path_edge;
  for (int i = 0; i < m; i++)
    if (dst == A[e[i].v] + e[i].w + B[e[i].u]) path_edge.push_back(i);
  sort(path_edge.begin(), path_edge.end(), [](int a, int b) {
    return pair<long long, long long>(e[a].r, -e[a].l) <
           pair<long long, long long>(e[b].r, -e[b].l);
  });
  int pes = path_edge.size();
  drpmax[pes][0] = drpmax[pes][1] = drpmax[pes][2] =
      pair<long long, int>(INF, pes);
  for (int i = pes - 1; i >= 0; i--) {
    drpmax[i][0] = drpmax[i + 1][0];
    drpmax[i][1] = drpmax[i + 1][1];
    drpmax[i][2] = pair<long long, int>(e[path_edge[i]].l, i);
    sort(drpmax[i], drpmax[i] + 3);
  }
  for (int i = 0; i < pes; i++) Rs[i] = e[path_edge[i]].r;
  for (int i = 0; i < pes; i++) {
    int pnt = upper_bound(Rs, Rs + pes, e[path_edge[i]].l) - Rs;
    long long mn = (drpmax[pnt][0].second == i ? drpmax[pnt][1].first
                                               : drpmax[pnt][0].first);
    forced[path_edge[i]] = !(mn < e[path_edge[i]].r);
  }
  for (int i = 0; i < m; i++)
    if (forced[i])
      cout << "YES" << endl;
    else if (dst - 1 - A[e[i].v] - B[e[i].u] > 0)
      cout << "CAN " << e[i].w - dst + 1LL + A[e[i].v] + B[e[i].u] << endl;
    else
      cout << "NO" << endl;
}
void dijkstra(int st, long long dis[], vector<pair<int, int> > graph[]) {
  for (int v = 0; v < n; v++) dis[v] = INF, mark[v] = false;
  dis[st] = 0;
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      pq;
  pq.push({0LL, st});
  while (!pq.empty()) {
    int h = pq.top().second;
    pq.pop();
    while (mark[h] && pq.size()) {
      h = pq.top().second;
      pq.pop();
    }
    if (mark[h]) break;
    mark[h] = true;
    for (auto [u, w] : graph[h])
      if (dis[u] > dis[h] + w) {
        dis[u] = dis[h] + w;
        pq.push({dis[u], u});
      }
  }
}
