#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5 + 5;
const int INF = 0x3f3f3f3f;
long long d1[MX], d2[MX];
int Head[MX], Next[MX], rear;
int Low[MX], DFN[MX], dfs_clock;
map<pair<long long, int>, int> R;
struct Edge {
  int u, v, cost, sign;
} E[MX], S[MX];
void edge_init() {
  rear = 0;
  memset(Head, -1, sizeof(Head));
}
void edge_add(int u, int v, int cost, int sign = 0) {
  E[rear].u = u;
  E[rear].v = v;
  E[rear].sign = sign;
  E[rear].cost = cost;
  Next[rear] = Head[u];
  Head[u] = rear++;
}
void dijistra(int Begin, long long *d) {
  memset(d, INF, sizeof(long long) * MX);
  d[Begin] = 0;
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      work;
  work.push(pair<long long, int>(0, Begin));
  while (!work.empty()) {
    pair<long long, int> f = work.top();
    work.pop();
    long long dist = f.first;
    int u = f.second;
    for (int id = Head[u]; ~id; id = Next[id]) {
      int cost = E[id].cost, v = E[id].v;
      if (dist + cost < d[v]) {
        d[v] = dist + cost;
        work.push(pair<long long, int>(dist + cost, v));
      }
    }
  }
}
void tarjan_init() {
  dfs_clock = 0;
  memset(DFN, 0, sizeof(DFN));
}
int tarjan(int u, int from) {
  Low[u] = DFN[u] = ++dfs_clock;
  int child = 0;
  for (int id = Head[u]; ~id; id = Next[id]) {
    int v = E[id].v;
    if (!DFN[v]) {
      int lowv = tarjan(v, u);
      Low[u] = min(Low[u], lowv);
      if (lowv > DFN[u]) {
        S[E[id].sign].sign = 1;
      }
      child++;
    } else if (v != from) {
      Low[u] = min(Low[u], DFN[v]);
    }
  }
  return Low[u];
}
int main() {
  int n, m, s, t;
  scanf("%d%d%d%d", &n, &m, &s, &t);
  edge_init();
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &S[i].u, &S[i].v, &S[i].cost);
    edge_add(S[i].v, S[i].u, S[i].cost);
    R[pair<long long, int>((long long)S[i].u * n + S[i].v, S[i].cost)]++;
  }
  dijistra(t, d2);
  edge_init();
  for (int i = 1; i <= m; i++) {
    edge_add(S[i].u, S[i].v, S[i].cost);
  }
  dijistra(s, d1);
  edge_init();
  for (int i = 1; i <= m; i++) {
    if (d1[S[i].u] + S[i].cost == d1[S[i].v] &&
        d2[S[i].v] + S[i].cost == d2[S[i].u]) {
      edge_add(S[i].u, S[i].v, S[i].cost, i);
      edge_add(S[i].v, S[i].u, S[i].cost, i);
    }
  }
  tarjan_init();
  tarjan(s, -1);
  for (int i = 1; i <= m; i++) {
    if (S[i].sign &&
        R[pair<long long, int>((long long)S[i].u * n + S[i].v, S[i].cost)] ==
            1) {
      printf("YES\n");
    } else {
      long long ans = d1[t] - d1[S[i].u] - d2[S[i].v] - 1;
      if (ans > 0)
        printf("CAN %d\n", S[i].cost - ans);
      else
        printf("NO\n");
    }
  }
  return 0;
}
