#include <bits/stdc++.h>
const int MAX = 1e5 + 5;
const long long INF = 9223372036854775807;
const int B = 1024;
const double M = 4e18;
using namespace std;
const int MOD = 1e9 + 7;
const int MAX_N = (int)1e5 + 123;
const double eps = 1e-6;
const long long inf = (long long)1e18 + 123;
using namespace std;
struct edge {
  int u, v, cost, id;
  void in(int _id) {
    id = _id;
    scanf("%d%d%d", &u, &v, &cost);
  }
  bool is_bridge;
} h[MAX_N];
int n, m, second, t;
long long dp[2][MAX_N];
vector<int> g[MAX_N], g_rev[MAX_N], first[MAX_N];
long long min_dist;
void do_it(int v, bool tp) {
  for (int i = 1; i <= n; i++) dp[tp][i] = inf;
  dp[tp][v] = 0;
  set<pair<long long, int> > q;
  q.insert(make_pair(0, v));
  while (!q.empty()) {
    int v = q.begin()->second;
    q.erase(q.begin());
    vector<int> &t = (!tp ? g[v] : g_rev[v]);
    for (auto i : t) {
      int to = (v ^ h[i].u ^ h[i].v);
      if (dp[tp][to] > dp[tp][v] + h[i].cost) {
        q.erase(make_pair(dp[tp][to], to));
        dp[tp][to] = dp[tp][v] + h[i].cost;
        q.insert(make_pair(dp[tp][to], to));
      }
    }
  }
  if (!tp) min_dist = dp[0][t];
}
int f_up[MAX_N], lvl[MAX_N];
bool u[MAX_N];
void dfs(int v, int pr = 0, int parent = 0) {
  f_up[v] = lvl[v] = lvl[parent] + 1;
  u[v] = 1;
  for (auto i : first[v]) {
    int to = (h[i].v ^ h[i].u ^ v);
    if (i == pr) continue;
    if (u[to] == 1)
      f_up[v] = min(f_up[v], lvl[to]);
    else {
      dfs(to, i, v);
      f_up[v] = min(f_up[v], f_up[to]);
      if (f_up[to] > lvl[v]) h[i].is_bridge = 1;
    }
  }
}
int main() {
  scanf("%d%d%d%d", &n, &m, &second, &t);
  for (int i = 1; i <= m; i++) {
    h[i].in(i);
    g[h[i].u].push_back(i);
    g_rev[h[i].v].push_back(i);
  }
  do_it(second, 0), do_it(t, 1);
  for (int i = 1; i <= m; i++) {
    if (dp[0][h[i].u] + h[i].cost + dp[1][h[i].v] == min_dist) {
      first[h[i].u].push_back(i);
      first[h[i].v].push_back(i);
    }
  }
  dfs(second);
  for (int i = 1; i <= m; i++) {
    if (h[i].is_bridge) {
      puts("YES");
      continue;
    }
    long long now = dp[0][h[i].u] + h[i].cost + dp[1][h[i].v];
    long long del = (now - (min_dist - 1));
    if (h[i].cost > del) {
      printf("CAN %d\n", (int)(del));
      continue;
    }
    puts("NO");
  }
  return 0;
}
