#include <bits/stdc++.h>
using namespace std;
const long long N = 100001;
const long long INF = 1e14;
vector<long long> nida[N];
vector<long long> ida_cost[N];
vector<long long> nvuelta[N];
vector<long long> vuelta_cost[N];
long long ida[N];
long long vuelta[N];
vector<long long> posible[N];
long long parent[N];
bool vis[N];
long long inicio[N];
map<pair<long long, long long>, bool> unico;
map<pair<long long, long long>, long long> mnpes;
map<pair<pair<long long, long long>, long long>, long long> cntari;
pair<pair<long long, long long>, long long> par[N];
void dijkstra_ida(long long x) {
  ida[x] = 0;
  priority_queue<pair<long long, long long> > q;
  q.push(make_pair(0, x));
  while (!q.empty()) {
    long long u = q.top().second;
    long long d_u = -q.top().first;
    q.pop();
    if (d_u != ida[u]) continue;
    long long sz = nida[u].size();
    for (long long i = 0; i < sz; i++) {
      long long v = nida[u][i];
      long long peso = ida_cost[u][i];
      if (ida[v] > ida[u] + peso) {
        ida[v] = ida[u] + peso;
        posible[v].clear();
        posible[v].push_back(u);
        q.push(make_pair(-ida[v], v));
      } else if (ida[v] == ida[u] + peso) {
        posible[v].push_back(u);
      }
    }
  }
  return;
}
void dfs(long long u, bool mult, long long viene) {
  vis[u] = true;
  long long sz = posible[u].size();
  for (long long i = 0; i < sz; i++) {
    long long v = posible[u][i];
    if (i == 0) {
      if (!vis[v]) {
        unico[make_pair(v, u)] = mult;
        parent[v] = u;
        dfs(v, mult, viene);
      } else {
        inicio[v] = viene;
      }
    } else {
      if (!vis[v]) {
        parent[v] = u;
        dfs(v, false, (viene == 0 ? u : viene));
      } else {
        inicio[v] = viene;
      }
    }
  }
  return;
}
void dijkstra_vuelta(long long x) {
  vuelta[x] = 0;
  priority_queue<pair<long long, long long> > q;
  q.push(make_pair(0, x));
  while (!q.empty()) {
    long long u = q.top().second;
    long long d_u = -q.top().first;
    q.pop();
    if (d_u != vuelta[u]) continue;
    long long sz = nvuelta[u].size();
    for (long long i = 0; i < sz; i++) {
      long long v = nvuelta[u][i];
      long long peso = vuelta_cost[u][i];
      if (vuelta[v] > vuelta[u] + peso) {
        vuelta[v] = vuelta[u] + peso;
        q.push(make_pair(-vuelta[v], v));
      }
    }
  }
  return;
}
void llena(long long u, long long x) {
  while (u != x) {
    unico[make_pair(u, parent[u])] = false;
    u = parent[u];
  }
  return;
}
int main() {
  for (long long i = 0; i < N; i++) {
    ida[i] = vuelta[i] = INF;
  }
  long long n, m, s, t;
  scanf("%lld %lld %lld %lld", &n, &m, &s, &t);
  long long x, y, w;
  for (long long i = 0; i < m; i++) {
    scanf("%lld %lld %lld", &x, &y, &w);
    nida[x].push_back(y);
    ida_cost[x].push_back(w);
    nvuelta[y].push_back(x);
    vuelta_cost[y].push_back(w);
    if (mnpes[make_pair(x, y)] == 0) {
      mnpes[make_pair(x, y)] = w;
    } else {
      mnpes[make_pair(x, y)] = min(mnpes[make_pair(x, y)], w);
    }
    par[i] = make_pair(make_pair(x, y), w);
    cntari[make_pair(make_pair(x, y), w)]++;
  }
  dijkstra_ida(s);
  dfs(t, true, 0);
  dijkstra_vuelta(t);
  long long dmn = ida[t];
  for (long long i = 1; i <= n; i++) {
    if (inicio[i] != 0) {
      llena(i, inicio[i]);
    }
  }
  for (long long i = 0; i < m; i++) {
    x = par[i].first.first;
    y = par[i].first.second;
    w = par[i].second;
    if (mnpes[par[i].first] == w && unico[par[i].first] &&
        cntari[par[i]] == 1) {
      printf("YES\n");
    } else {
      long long quita = ida[x] + vuelta[y] + w - dmn + 1;
      if (quita < w) {
        printf("CAN %lld\n", quita);
      } else {
        printf("NO\n");
      }
    }
  }
  return 0;
}
