#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int mod = 987654321;
vector<pair<int, int> > ad[N], rad[N];
vector<pair<pair<int, int>, int> > edge;
long long sdist[N], tdist[N], sway[N], tway[N];
void dijk(int s, int t, long long dis[], long long way[],
          vector<pair<int, int> > adj[]) {
  fill_n(dis, N, 1e18);
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      q;
  way[s] = 1;
  dis[s] = 0;
  q.push(make_pair(0, s));
  long long w, c;
  int v, u, i;
  while (!q.empty()) {
    w = q.top().first, v = q.top().second;
    q.pop();
    if (dis[v] != w) continue;
    if (v == t) continue;
    for (i = 0; i < adj[v].size(); ++i) {
      u = adj[v][i].first;
      c = adj[v][i].second;
      if (dis[u] >= w + c) {
        if (dis[u] == w + c) {
          way[u] = (way[u] + way[v]) % mod;
        } else {
          dis[u] = w + c;
          way[u] = way[v];
          q.push(make_pair(w + c, u));
        }
      }
    }
  }
}
int main() {
  int n, m, i, j, s, t, a, b, w;
  cin >> n >> m >> s >> t;
  for (i = 0; i < m; ++i) {
    cin >> a >> b >> w;
    ad[a].push_back(make_pair(b, w));
    rad[b].push_back(make_pair(a, w));
    edge.push_back(make_pair(make_pair(a, b), w));
  }
  dijk(s, t, sdist, sway, ad);
  dijk(t, s, tdist, tway, rad);
  long long mini = sdist[t], k;
  for (i = 0; i < m; ++i) {
    a = edge[i].first.first, b = edge[i].first.second, w = edge[i].second;
    if (sdist[a] + w + tdist[b] == mini && (sway[a] * tway[b]) % mod == sway[t])
      printf("YES\n");
    else {
      k = mini - 1 - sdist[a] - tdist[b];
      if (k > 0) {
        printf("CAN %d\n", (int)(w - k));
      } else
        printf("NO\n");
    }
  }
}
