#include <bits/stdc++.h>
using namespace std;
struct w {
  int a, b, c;
} ww[100005];
int n, m, s, t, ta, tb;
long long tc;
vector<int> to[100005], from[100005];
long long da[100005], db[100005], dd;
long long wa[100005], wb[100005], www;
pair<long long, int> pt;
priority_queue<pair<long long, int> > q;
int main() {
  scanf("%d%d%d%d", &n, &m, &s, &t);
  for (int a = 0; a < m; a++) {
    scanf("%d%d%d", &ww[a].a, &ww[a].b, &ww[a].c);
    to[ww[a].a].push_back(a);
    from[ww[a].b].push_back(a);
  }
  for (int a = 1; a <= n; a++) da[a] = db[a] = LLONG_MAX;
  q.push(make_pair(-0, s));
  da[s] = 0;
  wa[s] = 1;
  while (!q.empty()) {
    pt = q.top();
    q.pop();
    if (da[pt.second] != -pt.first) continue;
    for (int a = 0; a < to[pt.second].size(); a++) {
      if (da[pt.second] + ww[to[pt.second][a]].c < da[ww[to[pt.second][a]].b]) {
        da[ww[to[pt.second][a]].b] = da[pt.second] + ww[to[pt.second][a]].c;
        q.push(make_pair(-da[ww[to[pt.second][a]].b], ww[to[pt.second][a]].b));
        wa[ww[to[pt.second][a]].b] = wa[pt.second];
      } else if (da[pt.second] + ww[to[pt.second][a]].c ==
                 da[ww[to[pt.second][a]].b])
        wa[ww[to[pt.second][a]].b] =
            (wa[ww[to[pt.second][a]].b] + wa[pt.second]) % 1499999957;
    }
  }
  q.push(make_pair(-0, t));
  db[t] = 0;
  wb[t] = 1;
  while (!q.empty()) {
    pt = q.top();
    q.pop();
    if (db[pt.second] != -pt.first) continue;
    for (int a = 0; a < from[pt.second].size(); a++) {
      if (db[pt.second] + ww[from[pt.second][a]].c <
          db[ww[from[pt.second][a]].a]) {
        db[ww[from[pt.second][a]].a] = db[pt.second] + ww[from[pt.second][a]].c;
        q.push(
            make_pair(-db[ww[from[pt.second][a]].a], ww[from[pt.second][a]].a));
        wb[ww[from[pt.second][a]].a] = wb[pt.second];
      } else if (db[pt.second] + ww[from[pt.second][a]].c ==
                 db[ww[from[pt.second][a]].a])
        wb[ww[from[pt.second][a]].a] =
            (wb[ww[from[pt.second][a]].a] + wb[pt.second]) % 1499999957;
    }
  }
  dd = da[t];
  www = wa[t];
  for (int a = 0; a < m; a++) {
    if (da[ww[a].a] == LLONG_MAX || db[ww[a].b] == LLONG_MAX)
      printf("NO\n");
    else if (da[ww[a].a] + ww[a].c + db[ww[a].b] == dd &&
             (wa[ww[a].a] * wb[ww[a].b]) % 1499999957 == www)
      printf("YES\n");
    else {
      tc = dd - 1 - da[ww[a].a] - db[ww[a].b];
      if (tc <= 0)
        printf("NO\n");
      else
        printf("CAN %I64d\n", ww[a].c - tc);
    }
  }
  return 0;
}
