#include <bits/stdc++.h>
using namespace std;
struct value {
  long long v1, v2;
  value operator+(value b) {
    return {(v1 + b.v1) % 1000000007, (v2 + b.v2) % 1000000009};
  }
  bool operator==(value b) { return v1 == b.v1 && v2 == b.v2; }
  value operator*(value b) {
    return {(v1 * b.v1) % 1000000007, (v2 * b.v2) % 1000000009};
  }
};
long long S, T, n, m, x, y, z;
struct Dijkstra {
  vector<vector<pair<int, int> > > edges;
  vector<value> ways;
  vector<long long> distances;
  Dijkstra(vector<vector<pair<int, int> > > E) : edges(E) {
    for (int i = 0; i < n; i++) ways.push_back({0, 0});
    for (int i = 0; i < n; i++) distances.push_back(1000000000000000);
    priority_queue<pair<long long, long long> > pq;
    distances[S] = 0;
    ways[S] = {1, 1};
    pq.push(make_pair(0, S));
    while (pq.size()) {
      long long d = -pq.top().first;
      long long p = pq.top().second;
      pq.pop();
      if (distances[p] < d) continue;
      for (int i = 0; i < edges[p].size(); i++) {
        long long nd = d + edges[p][i].second;
        int other = edges[p][i].first;
        if (distances[other] > nd) {
          distances[other] = nd;
          ways[other] = ways[p];
          pq.push(make_pair(-nd, other));
        } else if (distances[other] == nd) {
          ways[other] = ways[p] + ways[other];
        }
      }
    }
  }
};
vector<vector<pair<int, int> > > edges, transpose;
vector<pair<pair<int, int>, int> > E;
int main() {
  scanf("%lld%lld%lld%lld", &n, &m, &S, &T);
  for (int i = 0; i < m; i++) {
  }
  edges.resize(n), transpose.resize(n);
  S--, T--;
  for (int i = 0; i < m; i++) {
    scanf("%lld%lld%lld", &x, &y, &z);
    x--, y--, z;
    edges[x].push_back({y, z});
    transpose[y].push_back(make_pair(x, z));
    E.push_back(make_pair(make_pair(x, y), z));
  }
  Dijkstra from(edges);
  swap(S, T);
  Dijkstra to(transpose);
  swap(S, T);
  for (int i = 0; i < m; i++) {
    value tot = from.ways[T];
    value ed = from.ways[E[i].first.first] * to.ways[E[i].first.second];
    if (tot == ed && E[i].second + from.distances[E[i].first.first] +
                             to.distances[E[i].first.second] ==
                         from.distances[T]) {
      printf("YES\n");
    } else {
      long long d = from.distances[T];
      long long x;
      x = d - 1 - from.distances[E[i].first.first] -
          to.distances[E[i].first.second];
      if (x <= 0)
        printf("NO\n");
      else
        printf("CAN %lld\n", E[i].second - x);
    }
  }
}
