#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > g[100000], rev[100000];
int from[100000], to[100000], w[100000];
long long dist[100000] = {}, distR[100000] = {};
const long long INF = 1e14;
int s, t;
int ways[2][100000] = {}, waysR[2][100000] = {};
const int MOD[2] = {1000000007, 1000000009};
struct Cmp {
  inline bool operator()(const int &lhs, const int &rhs) const {
    if (dist[lhs] != dist[rhs]) return dist[lhs] < dist[rhs];
    return lhs < rhs;
  }
};
struct CmpR {
  inline bool operator()(const int &lhs, const int &rhs) const {
    if (distR[lhs] != distR[rhs]) return distR[lhs] < distR[rhs];
    return lhs < rhs;
  }
};
set<int, Cmp> q;
set<int, CmpR> qr;
int main() {
  scanf("%d%d%d%d", &n, &m, &s, &t), --s, --t;
  for (int i = 0; i < (int)(m); ++i) {
    scanf("%d%d%d", from + i, to + i, w + i), --from[i], --to[i];
    g[from[i]].push_back(make_pair(to[i], w[i]));
    rev[to[i]].push_back(make_pair(from[i], w[i]));
  }
  for (int i = 0; i < (int)(n); ++i) dist[i] = INF;
  dist[s] = 0;
  q.insert(s);
  ways[0][s] = ways[1][s] = 1;
  while (!q.empty()) {
    int v = *q.begin();
    q.erase(q.begin());
    for (pair<int, int> to : g[v])
      if (dist[to.first] > dist[v] + to.second) {
        q.erase(to.first);
        dist[to.first] = dist[v] + to.second;
        for (int z = 0; z < (int)(2); ++z) ways[z][to.first] = ways[z][v];
        q.insert(to.first);
      } else if (dist[to.first] == dist[v] + to.second) {
        for (int z = 0; z < (int)(2); ++z) {
          ways[z][to.first] += ways[z][v];
          if (ways[z][to.first] >= MOD[z]) {
            ways[z][to.first] -= MOD[z];
          }
        }
      }
  }
  for (int i = 0; i < (int)(n); ++i) distR[i] = INF;
  distR[t] = 0;
  qr.insert(t);
  waysR[0][t] = waysR[1][t] = 1;
  while (!qr.empty()) {
    int v = *qr.begin();
    qr.erase(qr.begin());
    for (pair<int, int> to : rev[v])
      if (distR[to.first] > distR[v] + to.second) {
        qr.erase(to.first);
        distR[to.first] = distR[v] + to.second;
        for (int z = 0; z < (int)(2); ++z) waysR[z][to.first] = waysR[z][v];
        qr.insert(to.first);
      } else if (distR[to.first] == distR[v] + to.second) {
        for (int z = 0; z < (int)(2); ++z) {
          waysR[z][to.first] += waysR[z][v];
          if (waysR[z][to.first] >= MOD[z]) {
            waysR[z][to.first] -= MOD[z];
          }
        }
      }
  }
  long long tot = dist[t];
  for (int i = 0; i < (int)(m); ++i) {
    if (dist[from[i]] + w[i] + distR[to[i]] == tot) {
      bool flag = true;
      for (int z = 0; z < (int)(2); ++z) {
        int curW = (long long)ways[z][from[i]] * waysR[z][to[i]] % MOD[z];
        if (curW != ways[z][t]) {
          flag = false;
          break;
        }
      }
      if (flag) {
        printf("YES\n");
      } else if (w[i] > 1) {
        printf("CAN 1\n");
      } else {
        printf("NO\n");
      }
    } else {
      long long targ = tot - dist[from[i]] - distR[to[i]] - 1;
      if (targ < 1) {
        printf("NO\n");
      } else {
        printf("CAN %d\n", (int)(w[i] - targ));
      }
    }
  }
  return 0;
}
