#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3f3f3f3f3fll;
const double pi = acos(-1);
const int mod = 1e9 + 7;
vector<pair<long long, pair<int, int> > > edge;
int n, m, s, t;
vector<vector<long long> > g, gl, spg;
vector<int> memo, lvl, bridge;
vector<long long> ds, dt;
void dijkstra(vector<vector<long long> > &g, int o, vector<long long> &d) {
  priority_queue<pair<long long, long long> > pq;
  pq.push(make_pair(0, o));
  d[o] = 0;
  while (!pq.empty()) {
    pair<long long, long long> now = pq.top();
    pq.pop();
    now.first *= -1;
    if (d[now.second] != now.first) continue;
    for (int e : g[now.second]) {
      int to = now.second == edge[e].second.first ? edge[e].second.second
                                                  : edge[e].second.first;
      if (edge[e].first + now.first < d[to]) {
        d[to] = edge[e].first + now.first;
        pq.push(make_pair(-d[to], to));
      }
    }
  }
}
void buildSPG() {
  long long d = ds[t];
  int i = 0;
  for (pair<long long, pair<int, int> > e : edge) {
    if (ds[e.second.first] + e.first + dt[e.second.second] == d) {
      spg[e.second.first].push_back(i);
      spg[e.second.second].push_back(i);
      bridge[i] = 1;
    }
    i++;
  }
}
void findBridges(int u, int l, int from) {
  lvl[u] = l;
  for (int e : spg[u]) {
    if (e == from) continue;
    int v = edge[e].second.first == u ? edge[e].second.second
                                      : edge[e].second.first;
    if (lvl[v] < 0) findBridges(v, l + 1, e);
    if (memo[v] <= l or lvl[v] <= l)
      bridge[e] = 0, memo[u] = min(memo[u], lvl[v]);
    memo[u] = min(memo[u], memo[v]);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%d%d", &s, &t);
  --s, --t;
  g.resize(n);
  gl.resize(n);
  edge.resize(m);
  long long a, b, w;
  for (int i = 0; i < m; i++) {
    scanf("%lld%lld%lld", &a, &b, &w);
    --a, --b;
    edge[i] = make_pair(w, make_pair(a, b));
    g[a].push_back(i);
    gl[b].push_back(i);
  }
  ds.assign(n, linf);
  dt.assign(n, linf);
  dijkstra(g, s, ds);
  dijkstra(gl, t, dt);
  g.clear();
  gl.clear();
  bridge.assign(m, 0);
  spg.resize(n);
  buildSPG();
  lvl.assign(n, -1);
  memo.assign(n, inf);
  findBridges(s, 0, -1);
  int i = 0;
  for (pair<long long, pair<int, int> > e : edge) {
    long long d = ds[e.second.first] + e.first + dt[e.second.second];
    if (bridge[i])
      printf("YES\n");
    else if (ds[e.second.first] + 1 + dt[e.second.second] < ds[t])
      printf("CAN %lld\n", d - ds[t] + 1);
    else
      printf("NO\n");
    i++;
  }
  return 0;
}
