#include <bits/stdc++.h>
using namespace std;
long long const N = 1e5 + 100, INF = 1ll * 1e9 * 1e9 + 100;
long long n, m, s, t;
long long h[N], d[N], dis[2][N], ans[N];
pair<pair<long long, long long>, long long> e[N];
vector<long long> f[N], g[N];
set<pair<long long, long long> > st;
bool vis[N];
void dij(bool b, long long s) {
  dis[b][s] = 0;
  st.insert({0, s});
  while (st.size()) {
    long long v = st.begin()->second;
    st.erase(st.begin());
    for (long long i : g[v]) {
      long long u = e[i].first.first + e[i].first.second - v, w = e[i].second;
      if (b ^ (u != e[i].first.second)) continue;
      if (dis[b][v] + w < dis[b][u]) {
        st.erase({dis[b][u], u});
        dis[b][u] = dis[b][v] + w;
        st.insert({dis[b][u], u});
      }
    }
  }
}
void cut_edge(long long v = 0, long long i = -1) {
  long long p = (~i ? e[i].first.first + e[i].first.second - v : -1);
  vis[v] = 1;
  d[v] = h[v];
  for (long long j : f[v]) {
    long long u = e[j].first.first + e[j].first.second - v;
    if (vis[u]) {
      if (i != j) {
        ans[j] = 1;
        d[v] = min(d[v], h[u]);
        if (h[u] == h[p]) ans[i] = 1;
      }
      continue;
    }
    h[u] = h[v] + 1;
    cut_edge(u, j);
    if (d[u] != h[u]) ans[j] = 1;
    d[v] = min(d[v], d[u]);
  }
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  fill(d, d + N, INF);
  fill(dis[0], dis[0] + N, INF);
  fill(dis[1], dis[1] + N, INF);
  cin >> n >> m >> s >> t;
  s--, t--;
  for (long long i = 0, u, v, w; i < m; i++) {
    cin >> u >> v >> w;
    u--, v--;
    e[i] = {{u, v}, w};
    g[u].push_back(i);
    g[v].push_back(i);
  }
  dij(0, s), dij(1, t);
  for (long long i = 0; i < m; i++) {
    long long u = e[i].first.first, v = e[i].first.second, w = e[i].second;
    long long path = dis[0][u] + w + dis[1][v];
    if (path == dis[0][t]) {
      f[u].push_back(i);
      f[v].push_back(i);
    } else {
      ans[i] = path - dis[0][t] + 1;
    }
  }
  cut_edge(s);
  for (long long i = 0; i < m; i++) {
    long long w = e[i].second;
    if (w - ans[i] <= 0)
      cout << "NO\n";
    else if (!ans[i])
      cout << "YES\n";
    else
      cout << "CAN " << ans[i] << '\n';
  }
}
