#include <bits/stdc++.h>
using namespace std;
const long long maxN = 1e5 + 10;
const long long MOD = 1e9 + 17;
long long s, t, n, m;
long long d[2][maxN];
vector<pair<long long, long long> > g[maxN], h[maxN];
vector<pair<pair<long long, long long>, long long> > edge;
long long dp[2][maxN];
void dij0(long long source) {
  fill(d[0], d[0] + maxN, 1e18 + 10);
  d[0][source] = 0;
  dp[0][source] = 1;
  set<pair<long long, long long> > s;
  s.insert(make_pair(d[0][source], source));
  while (!s.empty()) {
    long long v = s.begin()->second;
    s.erase(s.begin());
    for (long long i = 0; i < g[v].size(); i++) {
      long long u = g[v][i].first, w = g[v][i].second;
      if (d[0][u] > d[0][v] + w) {
        dp[0][u] = dp[0][v] % MOD;
        s.erase(make_pair(d[0][u], u));
        d[0][u] = d[0][v] + w;
        s.insert(make_pair(d[0][u], u));
      } else if (d[0][u] == d[0][v] + w)
        dp[0][u] += dp[0][v], dp[0][u] %= MOD;
    }
  }
}
void dij1(long long source) {
  fill(d[1], d[1] + maxN, 1e18 + 10);
  d[1][source] = 0;
  dp[1][source] = 1;
  set<pair<long long, long long> > s;
  s.insert(make_pair(d[1][source], source));
  while (!s.empty()) {
    long long v = s.begin()->second;
    s.erase(s.begin());
    for (long long i = 0; i < h[v].size(); i++) {
      long long u = h[v][i].first, w = h[v][i].second;
      if (d[1][u] > d[1][v] + w) {
        dp[1][u] = dp[1][v] % MOD;
        s.erase(make_pair(d[1][u], u));
        d[1][u] = d[1][v] + w;
        s.insert(make_pair(d[1][u], u));
      } else if (d[1][u] == d[1][v] + w)
        dp[1][u] += dp[1][v], dp[1][u] %= MOD;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> s >> t;
  s--;
  t--;
  for (long long i = 0; i < m; i++) {
    long long v, u, w;
    cin >> v >> u >> w;
    v--, u--;
    g[v].push_back(make_pair(u, w));
    h[u].push_back(make_pair(v, w));
    edge.push_back(make_pair(make_pair(v, u), w));
  }
  dij0(s);
  dij1(t);
  for (long long i = 0; i < m; i++) {
    long long v = edge[i].first.first, u = edge[i].first.second;
    long long w = edge[i].second;
    if (d[0][v] + w + d[1][u] == d[0][t]) {
      if ((dp[0][v] * dp[1][u]) % MOD == dp[0][t]) {
        cout << "YES" << '\n';
        continue;
      }
    }
    if (d[0][v] + d[1][u] + 1 < d[0][t]) {
      cout << "CAN " << d[0][v] + w + d[1][u] - d[0][t] + 1 << '\n';
      continue;
    }
    cout << "NO" << '\n';
  }
  return 0;
}
