#include <bits/stdc++.h>
using namespace std;
long long n, m, s, t;
struct rode {
  long long y, next, z;
} e[100010 << 1] = {};
long long fl[2][100010] = {};
long long len = 0;
inline long long read() {
  long long s = 0, w = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '0') c = getchar();
  if (c == '-') w = -1, c = getchar();
  while (c <= '9' && c >= '0') s = (s << 3) + (s << 1) + c - '0', c = getchar();
  return s * w;
}
inline void inc(long long x, long long y, long long z) {
  e[++len].y = y;
  e[len].z = z;
  e[len].next = fl[0][x];
  fl[0][x] = len;
  e[++len].y = x;
  e[len].z = z;
  e[len].next = fl[1][y];
  fl[1][y] = len;
}
long long dis[2][100010] = {};
bool vis[100010] = {};
long long si[2][100010] = {};
void DJ(long long st, long long p) {
  memset(dis[p], 0x3f, sizeof dis[p]);
  memset(vis, 0, sizeof vis);
  priority_queue<pair<long long, long long> > q;
  si[p][st] = 1;
  dis[p][st] = 0;
  q.push(make_pair(0, st));
  while (!q.empty()) {
    long long tm = q.top().second;
    q.pop();
    if (vis[tm]) continue;
    vis[tm] = 1;
    for (long long i = fl[p][tm]; i; i = e[i].next) {
      long long v = e[i].y;
      if (dis[p][e[i].y] > dis[p][tm] + e[i].z) {
        dis[p][v] = dis[p][tm] + e[i].z;
        si[p][v] = si[p][tm];
        q.push(make_pair(-dis[p][v], v));
      } else if (dis[p][v] == dis[p][tm] + e[i].z)
        si[p][v] += si[p][tm], si[p][v] %= 0x3f3f3f3f;
    }
  }
}
struct node {
  long long x, y, z;
} b[100010 << 1] = {};
signed main() {
  cin >> n >> m >> s >> t;
  for (long long i = 1; i <= m; ++i) {
    cin >> b[i].x >> b[i].y >> b[i].z;
    inc(b[i].x, b[i].y, b[i].z);
  }
  DJ(s, 0);
  DJ(t, 1);
  for (long long i = 1; i <= m; ++i) {
    long long u = b[i].x, v = b[i].y;
    if (dis[0][u] + dis[1][v] + b[i].z == dis[0][t]) {
      if (si[0][u] * si[1][v] % 0x3f3f3f3f == si[0][t])
        puts("YES");
      else if (b[i].z > 1)
        printf("CAN %d\n", 1);
      else
        puts("NO");
    } else {
      if (dis[0][u] + dis[1][v] + 1 < dis[0][t])
        printf("CAN %lld\n", dis[0][u] + dis[1][v] + b[i].z - dis[0][t] + 1);
      else
        puts("NO");
    }
  }
  return 0;
}
