#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 3;
struct edge {
  int from, to, w, id;
};
vector<edge> arist;
int k = 0, n, s, t, m, td[MAXN], low[MAXN], memo[MAXN], bridges[MAXN];
vector<edge> G[MAXN], GT[MAXN];
vector<edge> GM[MAXN];
long long d1[MAXN], d2[MAXN];
void dfs(int v, int id) {
  memo[v] = 1;
  td[v] = k++;
  low[v] = td[v];
  for (int i = (int)0; i < (int)GM[v].size(); i++) {
    int u = GM[v][i].to, nid = GM[v][i].id;
    if (!memo[u]) {
      dfs(u, nid);
      low[v] = min(low[v], low[u]);
      if (low[u] == td[u]) bridges[nid] = 1;
    } else if (nid != id)
      low[v] = min(low[v], td[u]);
  }
}
void dijk(int s, vector<edge> GD[], long long d[]) {
  memset(d, 0x3f, sizeof(d[0]) * (n + 4));
  d[s] = 0;
  priority_queue<pair<long long, int> > cola;
  vector<bool> marcas(n + 4, 0);
  cola.push({0, s});
  while (!cola.empty()) {
    int v = cola.top().second;
    cola.pop();
    if (!marcas[v]) {
      marcas[v] = 1;
      for (int i = (int)0; i < (int)GD[v].size(); i++) {
        int u = GD[v][i].to, ww = GD[v][i].w;
        if (d[v] + ww < d[u]) {
          d[u] = d[v] + ww;
          cola.push({-d[u], u});
        }
      }
    }
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &s);
  scanf("%d", &t);
  for (int i = (int)0; i < (int)m; i++) {
    edge e, e1;
    scanf("%d %d %d", &e.from, &e.to, &e.w);
    e.id = i;
    e1 = {e.to, e.from, e.w, i};
    G[e.from].push_back(e);
    GT[e1.from].push_back(e1);
    arist.push_back(e);
  }
  dijk(s, G, d1);
  dijk(t, GT, d2);
  for (int i = (int)0; i < (int)m; i++) {
    edge e = arist[i], e1 = arist[i];
    swap(e1.from, e1.to);
    int u = e.from, v = e.to, w = e.w;
    if (d1[u] + w + d2[v] == d1[t]) {
      GM[e.to].push_back(e1);
      GM[e.from].push_back(e);
    }
  }
  dfs(s, -1);
  for (int i = (int)0; i < (int)m; i++) {
    edge e = arist[i];
    int u = e.from, v = e.to, w = e.w;
    if (bridges[e.id])
      printf("YES\n");
    else {
      long long x = d1[u] + w + d2[v] - d1[t] + 1;
      if (w - x > 0)
        printf("CAN %lld\n", x);
      else
        printf("NO\n");
    }
  }
}
