#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
const long long INF = (long long)1e18;
int n, m, s, t;
int edge_a[N], edge_b[N], edge_w[N];
vector<pair<int, int>> go_for[N];
vector<pair<int, int>> go_back[N];
long long dist_for[N], dist_back[N];
long long *dist;
struct Cmp {
  bool operator()(int a, int b) const {
    if (dist[a] == dist[b]) return a < b;
    return dist[a] < dist[b];
  }
};
set<int, Cmp> q;
void calc_sp(int sv, vector<pair<int, int>> go[]) {
  fill(dist, dist + n, INF);
  dist[sv] = 0;
  q.insert(sv);
  while (!q.empty()) {
    int v = *q.begin();
    q.erase(q.begin());
    for (auto e : go[v]) {
      int to = e.first;
      int w = e.second;
      if (dist[to] > dist[v] + w) {
        q.erase(to);
        dist[to] = dist[v] + w;
        q.insert(to);
      }
    }
  }
}
vector<pair<int, int>> sp[N];
int height[N];
bool bridge[N];
int dfs(int v, int p, int h) {
  height[v] = h;
  int best = h;
  for (auto e : sp[v]) {
    int to = e.first;
    int ind = e.second;
    if (to == p) continue;
    if (height[to] == -1) {
      int ret = dfs(to, v, h + 1);
      if (ret > h) bridge[ind] = true;
      best = min(best, ret);
    } else
      best = min(best, height[to]);
  }
  return best;
}
void solve() {
  scanf("%d%d%d%d", &n, &m, &s, &t);
  s--;
  t--;
  for (int i = 0; i < m; i++) {
    int a, b, w;
    scanf("%d%d%d", &a, &b, &w);
    a--;
    b--;
    edge_a[i] = a;
    edge_b[i] = b;
    edge_w[i] = w;
    go_for[a].emplace_back(b, w);
    go_back[b].emplace_back(a, w);
  }
  dist = dist_for;
  calc_sp(s, go_for);
  dist = dist_back;
  calc_sp(t, go_back);
  for (int i = 0; i < m; i++) {
    int a = edge_a[i];
    int b = edge_b[i];
    int w = edge_w[i];
    if (dist_for[a] + w + dist_back[b] == dist_for[t]) {
      sp[a].emplace_back(b, i);
      sp[b].emplace_back(a, i);
    }
  }
  fill(height, height + n, -1);
  dfs(s, -1, 0);
  map<pair<int, int>, int> index;
  for (int v = 0; v < n; v++)
    for (auto e : sp[v]) {
      int to = e.first;
      int ind = e.second;
      auto p = make_pair(v, to);
      if (index.count(p) == 1) {
        bridge[index[p]] = false;
        bridge[ind] = false;
      } else
        index[p] = ind;
    }
  for (int i = 0; i < m; i++) {
    int a = edge_a[i];
    int b = edge_b[i];
    int w = edge_w[i];
    if (bridge[i]) {
      puts("YES");
      continue;
    }
    long long x = dist_for[t];
    long long y = dist_for[a] + dist_back[b];
    long long desired = x - y - 1;
    if (w < desired) throw;
    if (desired >= 1)
      printf("CAN %lld\n", w - desired);
    else
      printf("NO\n");
  }
}
int main() {
  solve();
  0;
  return 0;
}
