#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 1e5 + 5, inf = 1000000LL * 1000000LL * 1000000LL;
const long long MOD[] = {1000000007, 1000000009}, C = 2;
long long n, m, s, t;
long long path;
pair<pair<long long, long long>, long long> edge[MAX_N];
long long dis[2][MAX_N];
long long num[C][2][MAX_N];
vector<pair<long long, long long> > G[2][MAX_N];
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    PQ;
long long _sum(long long type, long long a, long long b) {
  long long c = a + b;
  if (MOD[type] <= c) c -= MOD[type];
  return c;
}
long long _mul(long long type, long long a, long long b) {
  long long c = a * b % MOD[type];
  return c;
}
void dijkstra(long long v, long long adj, long long type) {
  for (long long i = 0; i < n; i++) dis[type][i] = inf;
  dis[type][v] = 0;
  for (long long i = 0; i < C; i++) num[i][type][v] = 1;
  PQ.push({0, v});
  while (PQ.size()) {
    long long u = PQ.top().second;
    long long d = PQ.top().first;
    PQ.pop();
    if (dis[type][u] < d) continue;
    for (long long i = 0; i < G[adj][u].size(); i++) {
      if (dis[type][u] + G[adj][u][i].second == dis[type][G[adj][u][i].first])
        for (long long j = 0; j < C; j++)
          num[j][type][G[adj][u][i].first] =
              _sum(j, num[j][type][G[adj][u][i].first], num[j][type][u]);
      if (dis[type][u] + G[adj][u][i].second < dis[type][G[adj][u][i].first]) {
        dis[type][G[adj][u][i].first] = dis[type][u] + G[adj][u][i].second;
        for (long long j = 0; j < C; j++)
          num[j][type][G[adj][u][i].first] = num[j][type][u];
        PQ.push({dis[type][G[adj][u][i].first], G[adj][u][i].first});
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m >> s >> t;
  s--, t--;
  for (long long i = 0; i < m; i++) {
    long long v, u, w;
    cin >> v >> u >> w;
    v--;
    u--;
    G[0][v].push_back({u, w});
    G[1][u].push_back({v, w});
    edge[i] = {{v, u}, w};
  }
  dijkstra(s, 0, 0);
  dijkstra(t, 1, 1);
  path = dis[0][t];
  for (long long i = 0; i < m; i++) {
    long long v = edge[i].first.first;
    long long u = edge[i].first.second;
    long long w = edge[i].second;
    if (dis[0][v] + w + dis[1][u] == path) {
      bool ok = true;
      for (long long j = 0; j < C; j++)
        ok &= (_mul(j, num[j][0][v], num[j][1][u]) == num[j][0][t]);
      if (ok)
        cout << "YES\n";
      else {
        if (w == 1)
          cout << "NO\n";
        else
          cout << "CAN 1\n";
      }
    } else {
      if (path <= dis[0][v] + 1 + dis[1][u])
        cout << "NO\n";
      else
        cout << "CAN " << dis[0][v] + w + dis[1][u] - path + 1 << "\n";
    }
  }
  return 0;
}
