#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e18;
const int mod = 1e9 + 7, mod2 = 1e9 + 9;
const int N = 1e5 + 10;
int n, m, s, t;
bool vis[N];
long long c1[N], c2[N], dp[N][2][2];
struct state {
  int v;
  long long cost;
  state(int _v, long long _cost) { v = _v, cost = _cost; }
  bool operator<(const state &rhs) const { return cost > rhs.cost; }
};
vector<state> adj[N];
vector<pair<int, pair<int, int> > > E;
vector<int> g[N][2];
void dijsktra(int u, long long cost[]) {
  memset(vis, 0, sizeof vis);
  for (int i = 1; i <= n; ++i) cost[i] = oo;
  priority_queue<state> q;
  q.push(state(u, 0));
  cost[u] = 0;
  while (q.size()) {
    state src = q.top();
    q.pop();
    if (vis[src.v]) continue;
    vis[src.v] = 1;
    for (auto g : adj[src.v]) {
      long long newCost = g.cost + cost[src.v];
      if (newCost < cost[g.v]) {
        cost[g.v] = newCost;
        q.push(state(g.v, cost[g.v]));
      }
    }
  }
}
long long adl(long long a, long long b, long long mod) { return (a + b) % mod; }
long long mul(long long a, long long b, long long mod) { return (a * b) % mod; }
long long calc(int z, int type, int u) {
  if (type == 0 && u == t) return 1;
  if (type == 1 && u == s) return 1;
  long long &ret = dp[u][type][z];
  if (ret != -1) return ret;
  ret = 0;
  for (auto v : g[u][type]) ret = adl(ret, calc(z, type, v), !z ? mod : mod2);
  return ret;
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n >> m >> s >> t;
  for (int a, b, l, i = 0; i < m; ++i) {
    scanf("%d%d%d", &a, &b, &l);
    adj[a].push_back(state(b, l));
    E.push_back(make_pair(l, make_pair(a, b)));
  }
  dijsktra(s, c1);
  for (int i = 1; i <= n; ++i) adj[i].clear();
  for (auto v : E) {
    adj[v.second.second].push_back(state(v.second.first, v.first));
  }
  dijsktra(t, c2);
  for (auto f : E) {
    if (f.first + c1[f.second.first] + c2[f.second.second] == c1[t]) {
      g[f.second.first][0].push_back(f.second.second);
      g[f.second.second][1].push_back(f.second.first);
    }
  }
  for (auto f : E) {
    long long req = c1[t] - (c1[f.second.first] + c2[f.second.second]) - 1;
    long long ways =
        mul(calc(0, 1, f.second.first), calc(0, 0, f.second.second), mod);
    long long ways2 =
        mul(calc(1, 1, f.second.first), calc(1, 0, f.second.second), mod2);
    if (ways == calc(0, 0, s) && ways2 == calc(1, 0, s) &&
        c1[t] == c1[f.second.first] + c2[f.second.second] + f.first) {
      puts("YES");
    } else if (req <= 0) {
      puts("NO");
    } else {
      printf("CAN %lld\n", f.first - req);
    }
  }
  return 0;
}
