#include <bits/stdc++.h>
using namespace std;
const long long MAX = 200020;
const long long MOD = (long long)1e9 + 7;
const long long INF = 1e9;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const long double EPS = 1e-7;
vector<pair<long long, long long>> g[MAX];
vector<pair<long long, long long>> gt[MAX];
vector<pair<long long, long long>> adj[MAX];
priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
               greater<pair<long long, long long>>>
    pq;
long long n, m, s, t;
vector<bool> visited;
vector<long long> tin, low;
long long timer;
bool good[MAX];
void dfs(long long v, long long p = -1) {
  visited[v] = true;
  tin[v] = low[v] = timer++;
  for (auto par : adj[v]) {
    long long to, idx;
    tie(to, idx) = par;
    if (to == p) continue;
    if (visited[to])
      low[v] = min(low[v], tin[to]);
    else {
      dfs(to, v);
      low[v] = min(low[v], low[to]);
      if (low[to] > tin[v]) good[idx] = 1;
    }
  }
}
void find_bridges(long long n) {
  timer = 0;
  visited.assign(n, false);
  tin.assign(n, -1);
  low.assign(n, -1);
  for (long long i = 0; i < n; i++)
    if (!visited[i]) dfs(i);
}
void dijkstra(long long st, vector<long long>& d) {
  d[st] = 0;
  pq.push(make_pair(0, st));
  while (pq.size()) {
    long long u, dist;
    tie(dist, u) = pq.top();
    pq.pop();
    if (dist > d[u]) continue;
    for (auto par : g[u]) {
      long long v, w;
      tie(v, w) = par;
      if (dist + w < d[v]) {
        d[v] = dist + w;
        pq.push(make_pair(d[v], v));
      }
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> m >> s >> t;
  vector<tuple<long long, long long, long long>> edges;
  map<tuple<long long, long long, long long>, long long> med;
  for (long long i = 0; i < (long long)m; i++) {
    long long a, b, w;
    cin >> a >> b >> w;
    g[a].push_back(make_pair(b, w));
    gt[b].push_back(make_pair(a, w));
    edges.push_back(make_tuple(a, b, w));
    med[make_tuple(a, b, w)]++;
  }
  vector<long long> ds(n + 10, LLINF), dt(n + 10, LLINF);
  dijkstra(s, ds);
  swap(g, gt);
  dijkstra(t, dt);
  for (long long i = 0; i < (long long)m; i++) {
    long long a, b, w;
    tie(a, b, w) = edges[i];
    if (ds[a] + dt[b] + w == ds[t]) {
      adj[a].push_back(make_pair(b, i));
      adj[b].push_back(make_pair(a, i));
    }
  }
  find_bridges(n + 100);
  long long best = ds[t];
  for (long long i = 0; i < (long long)m; i++) {
    long long a, b, w;
    tie(a, b, w) = edges[i];
    long long val1 = ds[a] + dt[b] + 1LL * w;
    if (good[i] and med[make_tuple(a, b, w)] == 1) {
      cout << "YES" << '\n';
    } else if (val1 - best + 1 < w) {
      cout << "CAN " << val1 - best + 1 << '\n';
    } else {
      cout << "NO" << '\n';
    }
  }
  return 0;
}
