#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long N = 1e5 + 10, inf = 1e12 + 1;
long long lvl[N], mark[N], dis[N][2], ans[N], s, t;
vector<pair<pair<long long, long long>, long long> > edge, g[N][2];
vector<pair<long long, long long> > G[N];
void dijkstra(long long src, long long id) {
  for (long long i = 0; i < N; i++) dis[i][id] = inf;
  set<pair<long long, long long> > st;
  st.insert({0, src});
  dis[src][id] = 0;
  while (st.size()) {
    pair<long long, long long> p = *st.begin();
    st.erase(p);
    long long v = p.second;
    for (auto e : g[v][id]) {
      long long u = e.first.first, w = e.first.second;
      if (dis[u][id] > dis[v][id] + w) {
        st.erase({dis[u][id], u});
        dis[u][id] = dis[v][id] + w;
        st.insert({dis[u][id], u});
      }
    }
  }
}
long long dfs(long long v, long long e = -1, long long l = 0) {
  mark[v] = 1;
  lvl[v] = l;
  long long top = inf;
  for (auto E : G[v]) {
    long long u = E.first, id = E.second;
    if (mark[u] == 1 && id != e) {
      top = min(top, lvl[u]);
    }
    if (mark[u] == 0) top = min(top, dfs(u, id, l + 1));
  }
  if (e != -1) {
    if (top >= l) ans[e] = 0;
  }
  mark[v] = 2;
  return top;
}
void make_Graph() {
  for (long long i = 0; i < edge.size(); i++) {
    long long u = edge[i].first.first, v = edge[i].first.second,
              w = edge[i].second;
    if (dis[u][1] + w + dis[v][0] == dis[t][1]) {
      G[u].push_back({v, i});
      G[v].push_back({u, i});
    }
  }
}
int32_t main() {
  long long n, m;
  cin >> n >> m >> s >> t;
  for (long long i = 0; i < m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    g[u][1].push_back({{v, w}, i});
    g[v][0].push_back({{u, w}, i});
    edge.push_back({{u, v}, w});
  }
  dijkstra(s, 1);
  dijkstra(t, 0);
  for (long long i = 0; i < edge.size(); i++) {
    long long u = edge[i].first.first, v = edge[i].first.second,
              w = edge[i].second;
    if (dis[u][1] + 1 + dis[v][0] - dis[t][1] < 0)
      ans[i] = dis[u][1] + w + dis[v][0] - dis[t][1] + 1;
    else
      ans[i] = inf;
  }
  make_Graph();
  dfs(s);
  for (long long i = 0; i < m; i++) {
    if (ans[i] == 0) cout << "YES\n";
    if (ans[i] == inf) cout << "NO\n";
    if (ans[i] != 0 && ans[i] != inf) cout << "CAN " << ans[i] << "\n";
  }
  return 0;
}
