#include <bits/stdc++.h>
using namespace std;
template <class T>
void rd(T &x) {
  x = 0;
  int f = 1;
  char c;
  while (!isdigit(c = getchar()))
    if (c == '-') f = -1;
  do {
    x = (x << 3) + (x << 1) + (c ^ 48);
  } while (isdigit(c = getchar()));
  x *= f;
}
const int N = 1e5 + 5, mod = 998244323;
const long long INF = 0x3f3f3f3f3f3f3f3f;
struct node {
  int to, val, id;
};
vector<node> G[2][N];
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    Que;
int n, m, s, l;
long long dis[2][N], cnt[2][N], ans1[N], ans2[N], cost;
void dijkstra(int s, int f) {
  while (!Que.empty()) Que.pop();
  for (int i = 1; i <= n; i++) dis[f][i] = INF;
  dis[f][s] = 0;
  cnt[f][s] = 1;
  Que.push({0, s});
  while (!Que.empty()) {
    auto p = Que.top();
    Que.pop();
    long long u = p.second;
    if (dis[f][u] ^ p.first) continue;
    for (auto it : G[f][u]) {
      if (dis[f][it.to] > dis[f][u] + it.val) {
        dis[f][it.to] = dis[f][u] + it.val;
        cnt[f][it.to] = cnt[f][u];
        Que.push({dis[f][it.to], it.to});
      } else if (dis[f][it.to] == dis[f][u] + it.val)
        cnt[f][it.to] = (cnt[f][it.to] + cnt[f][u]) % mod;
    }
  }
}
int main() {
  rd(n), rd(m), rd(s), rd(l);
  for (int i = 1, a, b, c; i <= m; i++)
    rd(a), rd(b), rd(c), G[0][a].push_back({b, c, i}),
        G[1][b].push_back({a, c, i});
  dijkstra(s, 0);
  dijkstra(l, 1);
  for (int u = 1; u <= n; u++)
    for (auto it : G[0][u]) {
      if (dis[0][u] + dis[1][it.to] + it.val == dis[0][l])
        if (cnt[0][u] * cnt[1][it.to] % mod == cnt[0][l]) {
          ans1[it.id] = 1;
          continue;
        }
      cost = dis[0][u] + dis[1][it.to] + it.val - dis[0][l] + 1;
      if (it.val - cost > 0)
        ans1[it.id] = 0, ans2[it.id] = cost;
      else
        ans1[it.id] = -1;
    }
  for (int i = 1; i <= m; i++)
    if (ans1[i] == 1)
      puts("YES");
    else if (ans1[i] == -1)
      puts("NO");
    else
      printf("CAN %lld\n", ans2[i]);
  return 0;
}
