#include <bits/stdc++.h>
using namespace std;
const int maxN = 222222;
const long long INF = (long long)1e18;
int l[maxN], r[maxN], w[maxN], n, m, s, t, timer = 0, tin[maxN], fup[maxN];
bool flag[maxN], used[maxN];
long long d[2][maxN];
vector<pair<int, int> > g[maxN], g2[maxN], G[maxN];
priority_queue<pair<long long, int> > my;
void goDe(int num1, int v) {
  while (!my.empty()) my.pop();
  for (int i = 1; i <= n; ++i) d[num1][i] = INF;
  d[num1][v] = 0;
  my.push(make_pair(0, v));
  while (!my.empty()) {
    int v = my.top().second;
    long long W = -my.top().first;
    my.pop();
    for (int i = 0; i < g[v].size(); ++i) {
      int next = g[v][i].first;
      if (d[num1][next] > d[num1][v] + (long long)g[v][i].second) {
        d[num1][next] = d[num1][v] + (long long)g[v][i].second;
        my.push(make_pair(-d[num1][next], next));
      }
    }
  }
}
void goDe2(int num1, int v) {
  while (!my.empty()) my.pop();
  for (int i = 1; i <= n; ++i) d[num1][i] = INF;
  d[num1][v] = 0;
  my.push(make_pair(0, v));
  while (!my.empty()) {
    int v = my.top().second;
    long long W = -my.top().first;
    my.pop();
    for (int i = 0; i < g2[v].size(); ++i) {
      int next = g2[v][i].first;
      if (d[num1][next] > d[num1][v] + (long long)g2[v][i].second) {
        d[num1][next] = d[num1][v] + (long long)g2[v][i].second;
        my.push(make_pair(-d[num1][next], next));
      }
    }
  }
}
void dfs(int v, int p = -1) {
  used[v] = true;
  tin[v] = fup[v] = timer++;
  for (int i = 0; i < G[v].size(); ++i) {
    int to = G[v][i].first;
    if (to == p) continue;
    if (used[to])
      fup[v] = min(fup[v], tin[to]);
    else {
      dfs(to, v);
      fup[v] = min(fup[v], fup[to]);
      if (fup[to] > tin[v]) {
        flag[G[v][i].second] = true;
      }
    }
  }
}
bool myCmp(pair<int, int> a, pair<int, int> b) { return (a.first < b.first); }
int main() {
  scanf("%d %d %d %d\n", &n, &m, &s, &t);
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d %d\n", &l[i], &r[i], &w[i]);
    g[l[i]].push_back(make_pair(r[i], w[i]));
    g2[r[i]].push_back(make_pair(l[i], w[i]));
    flag[i] = false;
  }
  goDe(0, s);
  goDe2(1, t);
  for (int i = 1; i <= m; ++i) {
    if (d[0][l[i]] + (long long)w[i] + d[1][r[i]] == d[0][t]) {
      G[l[i]].push_back(make_pair(r[i], i));
      G[r[i]].push_back(make_pair(l[i], i));
    }
  }
  for (int i = 1; i <= n; ++i) {
    sort(G[i].begin(), G[i].end(), myCmp);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < G[i].size(); ++j) {
      int v1 = -1, v2 = -1;
      if (j != 0) v1 = G[i][j - 1].first;
      if ((j + 1) != G[i].size()) v2 = G[i][j + 1].first;
      if (v1 == G[i][j].first || v2 == G[i][j].first)
        flag[G[i][j].second] = false;
    }
  }
  for (int i = 1; i <= n; ++i) used[i] = false;
  for (int i = 1; i <= n; ++i) {
    if (used[i] == false) dfs(i);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < G[i].size(); ++j) {
      int v1 = -1, v2 = -1;
      if (j != 0) v1 = G[i][j - 1].first;
      if ((j + 1) != G[i].size()) v2 = G[i][j + 1].first;
      if (v1 == G[i][j].first || v2 == G[i][j].first)
        flag[G[i][j].second] = false;
    }
  }
  for (int i = 1; i <= m; ++i) {
    if (d[0][l[i]] == INF || d[1][r[i]] == INF) {
      printf("NO\n");
      continue;
    }
    if (d[0][l[i]] + (long long)w[i] + d[1][r[i]] != d[0][t]) {
      long long q = d[0][l[i]] + (long long)w[i] + d[1][r[i]] - d[0][t] + 1;
      long long curW = w[i] - q;
      if (curW <= 0)
        printf("NO\n");
      else
        printf("CAN %I64d\n", q);
    } else {
      if (flag[i])
        printf("YES\n");
      else if (w[i] > 1)
        printf("CAN 1\n");
      else
        printf("NO\n");
    }
  }
  return 0;
}
