#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const long long INF = (long long)1e17 + 10;
int n, m, s, t;
int a[N], b[N], l[N];
struct edge {
  int to, cost;
  edge(int to, int cost) : to(to), cost(cost) {}
};
vector<edge> e;
vector<int> g[N];
vector<int> g2[N];
long long diss[N], dist[N];
long long len;
bool vis[N], ans[N];
map<int, long long> mp;
set<pair<pair<long long, long long>, int> > st;
void dijkstra(int sc, vector<int> g[N], long long *dis) {
  fill(dis + 1, dis + n + 1, INF);
  priority_queue<pair<long long, int> > pq;
  pq.push(make_pair(0, sc));
  memset(vis, 0, sizeof(vis));
  while (!pq.empty()) {
    pair<long long, int> tmp = pq.top();
    pq.pop();
    if (vis[tmp.second]) continue;
    vis[tmp.second] = 1;
    dis[tmp.second] = -tmp.first;
    for (auto j : g[tmp.second]) {
      int u = e[j].to;
      int c = e[j].cost;
      if (vis[u]) continue;
      pair<long long, int> nxt = make_pair(-dis[tmp.second] - c, u);
      pq.push(nxt);
    }
  }
}
int main() {
  scanf("%d%d%d%d", &n, &m, &s, &t);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", a + i, b + i, l + i);
    g[a[i]].push_back(e.size());
    e.push_back(edge(b[i], l[i]));
    g2[b[i]].push_back(e.size());
    e.push_back(edge(a[i], l[i]));
  }
  dijkstra(s, g, diss);
  dijkstra(t, g2, dist);
  len = diss[t];
  for (int i = 0; i < m; ++i) {
    if (diss[a[i]] + dist[b[i]] + l[i] == len) {
      st.insert(make_pair(make_pair(diss[a[i]], diss[b[i]]), i));
      ans[i] = 1;
    }
  }
  long long mx = 0;
  for (auto k : st) {
    mp[k.second] = mx;
    mx = max(k.first.second, mx);
  }
  for (int i = 0; i < m; ++i) {
    if (diss[a[i]] + dist[b[i]] + l[i] == len) {
      st.erase(make_pair(make_pair(diss[a[i]], diss[b[i]]), i));
      auto it = st.lower_bound(make_pair(make_pair(diss[a[i]], -1), -1));
      if (!(it == st.end() || it->first.first == diss[b[i]])) {
        ans[i] = 0;
      }
      if (mp[i] > diss[a[i]]) {
        ans[i] = 0;
      }
      st.insert(make_pair(make_pair(diss[a[i]], diss[b[i]]), i));
    }
  }
  for (int i = 0; i < m; ++i) {
    if (ans[i]) {
      puts("YES");
    } else {
      long long mn = diss[a[i]] + dist[b[i]];
      if (len - 1 > mn) {
        printf("CAN %d\n", l[i] - (len - 1 - mn));
      } else {
        puts("NO");
      }
    }
  }
  return 0;
}
