#include <bits/stdc++.h>
using namespace std;
template <class T>
int getbit(T x, int pos) {
  return (x >> (pos - 1)) & 1;
}
template <class T>
void turn_on(T &x, int pos) {
  x = x | ((T)1 << (pos - 1));
}
template <class T>
void turn_off(T &x, int pos) {
  x = x & ~((T)1 << (pos - 1));
}
int read_int() {
  char r;
  bool start = false, neg = false;
  int ret = 0;
  while (true) {
    r = getchar();
    if ((r - '0' < 0 || r - '0' > 9) && r != '-' && !start) continue;
    if ((r - '0' < 0 || r - '0' > 9) && r != '-' && start) break;
    if (start) ret *= 10;
    start = true;
    if (r == '-')
      neg = true;
    else
      ret += r - '0';
  }
  if (!neg)
    return ret;
  else
    return -ret;
}
long long gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
const long long oo = 1e18 + 7;
const long long MOD = 987654321;
void Dijkstra(int s, vector<pair<long long, long long>> graph[],
              vector<long long> &dist, vector<long long> &cnt) {
  dist[s] = 0;
  cnt[s] = 1;
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      pq;
  pq.push(pair<long long, long long>(0, s));
  while (!pq.empty()) {
    int u = pq.top().second;
    long long du = pq.top().first;
    pq.pop();
    if (du != dist[u]) continue;
    for (auto v : graph[u]) {
      if (dist[v.first] >= dist[u] + v.second) {
        if (dist[v.first] == dist[u] + v.second) {
          cnt[v.first] = (cnt[u] + cnt[v.first]) % MOD;
        } else {
          dist[v.first] = dist[u] + v.second;
          cnt[v.first] = cnt[u];
          pq.push(pair<long long, long long>(dist[v.first], v.first));
        }
      }
    }
  }
}
int main() {
  srand(time(NULL));
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  vector<pair<long long, long long>> graph[n + 1], graph_re[n + 1];
  vector<long long> dist(n + 1, oo), dist_re(n + 1, oo), cnt(n + 1, 0),
      cnt_re(n + 1, 0);
  vector<pair<pair<long long, long long>, long long>> edge;
  while (m--) {
    int u, v, w;
    cin >> u >> v >> w;
    graph[u].push_back(pair<long long, long long>(v, w));
    graph_re[v].push_back(pair<long long, long long>(u, w));
    edge.push_back(pair<pair<long long, long long>, long long>(
        pair<long long, long long>(u, v), w));
  }
  Dijkstra(s, graph, dist, cnt);
  Dijkstra(t, graph_re, dist_re, cnt_re);
  for (auto x : edge) {
    int u = x.first.first;
    int v = x.first.second;
    int w = x.second;
    if (dist[u] + w + dist_re[v] == dist[t] &&
        (cnt[u] * cnt_re[v]) % MOD == cnt[t]) {
      cout << "YES\n";
      continue;
    }
    long long r = dist[t] - dist[u] - dist_re[v];
    if (r <= 1) {
      cout << "NO\n";
    } else {
      cout << "CAN " << w - r + 1 << "\n";
    }
  }
}
