#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 207;
const int N = (int)1e6 + 2;
long long n, m, s, t;
long long cnt1[N], cnt2[N];
long long D1[N], D2[N];
vector<pair<long long, long long> > G1[N], G2[N];
vector<pair<long long, pair<long long, long long> > > edge;
void solve1() {
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      pq;
  for (int i = 0; i <= n; i++) D1[i] = 1e14;
  D1[s] = 0;
  cnt1[s] = 1;
  pq.push(pair<long long, long long>(D1[s], s));
  while (!pq.empty()) {
    long long du = pq.top().first;
    long long u = pq.top().second;
    pq.pop();
    if (du != D1[u]) continue;
    for (int i = 0; i < G1[u].size(); i++) {
      long long v = G1[u][i].first;
      long long w = G1[u][i].second;
      if (D1[v] > du + w) {
        D1[v] = du + w;
        cnt1[v] = cnt1[u];
        pq.push(pair<long long, long long>(D1[v], v));
      } else if (D1[v] == du + w) {
        cnt1[v] += cnt1[u];
      }
      cnt1[v] %= mod;
    }
  }
}
void solve2() {
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      pq;
  for (int i = 0; i <= n; i++) D2[i] = 1e14;
  D2[t] = 0;
  cnt2[t] = 1;
  pq.push(pair<long long, long long>(D2[t], t));
  while (!pq.empty()) {
    long long du = pq.top().first;
    long long u = pq.top().second;
    pq.pop();
    if (du != D2[u]) continue;
    for (int i = 0; i < G2[u].size(); i++) {
      long long v = G2[u][i].first;
      long long w = G2[u][i].second;
      if (D2[v] > du + w) {
        D2[v] = du + w;
        cnt2[v] = cnt2[u];
        pq.push(pair<long long, long long>(D2[v], v));
      } else if (D2[v] == du + w) {
        cnt2[v] += cnt2[u];
      }
      cnt2[v] %= mod;
    }
  }
}
int main() {
  cin >> n >> m >> s >> t;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    edge.push_back(pair<long long, pair<long long, long long> >(
        w, pair<long long, long long>(u, v)));
    G1[u].push_back(pair<long long, long long>(v, w));
    G2[v].push_back(pair<long long, long long>(u, w));
  }
  solve1();
  solve2();
  for (int i = 0; i < m; i++) {
    long long u = edge[i].second.first;
    long long v = edge[i].second.second;
    long long w = edge[i].first;
    if (D1[u] + w + D2[v] == D1[t] &&
        ((1LL * cnt1[u] * cnt2[v]) % mod) == cnt1[t]) {
      cout << "YES\n";
    } else if (D1[u] + D2[v] + 1 < D1[t]) {
      cout << "CAN " << w - (D1[t] - D1[u] - D2[v] - 1) << "\n";
    } else
      cout << "NO\n";
  }
}
