#include <bits/stdc++.h>
using namespace std;
struct Tgraph {
  static const int maxn = 200010, maxm = 200010;
  struct Tedge {
    int idx, son, dis;
    Tedge *pre;
    void add(int i_, int s_, int d_, Tedge *p_) {
      idx = i_, son = s_, dis = d_, pre = p_;
    }
  } edge[maxm], *pos[maxn];
  int tot;
  void add(int i, int a, int b, int c) {
    edge[++tot].add(i, b, c, pos[a]), pos[a] = edge + tot;
  }
  void clear() {
    tot = 0;
    memset(pos, 0, sizeof(pos));
  }
} g, og, spt;
const long long inf = ~0ull >> 3;
const int maxn = 200010, maxm = 200010;
struct edge {
  int u, v, dis;
} e[maxm];
int n, m, st, ed;
void init() {
  scanf("%d%d%d%d", &n, &m, &st, &ed);
  g.clear(), og.clear();
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].dis);
    g.add(i, e[i].u, e[i].v, e[i].dis);
    og.add(i, e[i].v, e[i].u, e[i].dis);
  }
}
void dijkstra(const Tgraph &g, int s, long long d[], int pre[]) {
  static priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                        greater<pair<long long, int> > >
      heap;
  static bool upd[maxn];
  for (int i = 1; i <= n; ++i) d[i] = inf, pre[i] = -1, upd[i] = false;
  d[s] = 0, pre[s] = 0,
  heap = priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                        greater<pair<long long, int> > >();
  heap.push(make_pair(d[s], s));
  while (!heap.empty()) {
    int x = heap.top().second;
    heap.pop();
    if (upd[x]) continue;
    upd[x] = true;
    for (Tgraph::Tedge *i = g.pos[x]; i; i = i->pre)
      if (!upd[i->son] && d[i->son] > d[x] + i->dis) {
        d[i->son] = d[x] + i->dis, pre[i->son] = i->idx;
        heap.push(make_pair(d[i->son], i->son));
      }
  }
}
long long ds[maxn], dt[maxn];
bool inpath[maxm], inspt[maxm];
int pre[maxn], dep[maxn];
void preset() {
  dijkstra(og, ed, dt, pre);
  dijkstra(g, st, ds, pre);
  static int path[maxn];
  int sum = 0;
  memset(inpath, false, sizeof(inpath));
  for (int i = ed; i != st; i = e[pre[i]].u)
    inpath[pre[i]] = true, path[++sum] = i;
  path[++sum] = st;
  memset(dep, -1, sizeof(dep));
  for (int i = 1; i <= sum; ++i) dep[path[i]] = sum - i + 1;
  spt.clear();
  memset(inspt, false, sizeof(inspt));
  for (int i = 1; i <= m; ++i)
    if (ds[e[i].u] + e[i].dis + dt[e[i].v] == ds[ed])
      spt.add(i, e[i].u, e[i].v, e[i].dis);
  for (int p = sum; p >= 1; --p) {
    static int q[maxn];
    int top = 1;
    q[1] = path[p];
    for (int k = 1; k <= top; ++k) {
      for (Tgraph::Tedge *i = spt.pos[q[k]]; i; i = i->pre)
        if (dep[i->son] == -1) dep[i->son] = sum - p + 1, q[++top] = i->son;
    }
  }
}
int cnt[maxn];
void solve() {
  memset(cnt, 0, sizeof(cnt));
  for (int i = 1; i <= m; ++i)
    if (!inpath[i] && (ds[e[i].u] + e[i].dis + dt[e[i].v] == ds[ed])) {
      if (dep[e[i].u] <= dep[e[i].v] - 1)
        ++cnt[dep[e[i].u]], --cnt[dep[e[i].v]];
    }
  for (int i = 1; i <= n; ++i) cnt[i] += cnt[i - 1];
  for (int i = 1; i <= m; ++i)
    if (ds[e[i].u] + e[i].dis + dt[e[i].v] != ds[ed]) {
      long long newdis = ds[ed] - ds[e[i].u] - dt[e[i].v] - 1;
      if (newdis > 0)
        printf("CAN %d\n", e[i].dis - newdis);
      else
        puts("NO");
    } else if (!inpath[i]) {
      if (e[i].dis == 1)
        puts("NO");
      else
        puts("CAN 1");
    } else {
      if (cnt[dep[e[i].u]])
        if (e[i].dis == 1)
          puts("NO");
        else
          puts("CAN 1");
      else
        puts("YES");
    }
}
int main() {
  init();
  preset();
  solve();
  return 0;
}
