#include <bits/stdc++.h>
using namespace std;
void Dijkstra(int start, vector<vector<pair<int, int>>>& graph,
              vector<long long>& dist) {
  const long long INF = 1e12;
  for (int i = 0; i < dist.size(); i++) {
    dist[i] = INF;
  }
  dist[start] = 0;
  set<pair<long long, int>> order;
  order.insert({0, start});
  for (; !order.empty();) {
    int v = order.begin()->second;
    order.erase(order.begin());
    for (int i = 0; i < graph[v].size(); i++) {
      if (dist[v] + graph[v][i].first < dist[graph[v][i].second]) {
        order.erase({dist[graph[v][i].second], graph[v][i].second});
        dist[graph[v][i].second] = dist[v] + graph[v][i].first;
        order.insert({dist[graph[v][i].second], graph[v][i].second});
      }
    }
  }
  return;
}
int main() {
  int n, m, s, t;
  int a[100000], b[100000], ans[100000];
  long long l[100000];
  vector<vector<pair<int, int>>> graph;
  vector<vector<pair<int, int>>> reversed_graph;
  vector<long long> dist;
  vector<long long> reversed_dist;
  vector<pair<long long, pair<bool, int>>> event;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> s >> t;
  s--;
  t--;
  graph.resize(n);
  reversed_graph.resize(n);
  dist.resize(n);
  reversed_dist.resize(n);
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> l[i];
    a[i]--;
    b[i]--;
    graph[a[i]].push_back({l[i], b[i]});
    reversed_graph[b[i]].push_back({l[i], a[i]});
  }
  Dijkstra(s, graph, dist);
  Dijkstra(t, reversed_graph, reversed_dist);
  for (int i = 0; i < m; i++) {
    if (dist[a[i]] + l[i] + reversed_dist[b[i]] == dist[t]) {
      event.push_back({dist[b[i]], {0, i}});
      event.push_back({dist[a[i]], {1, i}});
    }
  }
  sort(event.begin(), event.end());
  int counter = 0;
  bool wasOne = 1;
  memset(ans, 0, sizeof(ans));
  for (int i = 0; i < event.size(); i++) {
    if (event[i].second.first == 0) {
      if (wasOne) {
        wasOne = 0;
        ans[event[i].second.second] = -1;
      }
      counter--;
    } else {
      if (counter == 0) {
        wasOne = 1;
      } else if (counter == 1) {
        wasOne = 0;
      }
      counter++;
    }
  }
  for (int i = 0; i < m; i++) {
    if (ans[i] == 0) {
      if (dist[t] - dist[a[i]] - reversed_dist[b[i]] - 1 > 0) {
        ans[i] = l[i] - (dist[t] - dist[a[i]] - reversed_dist[b[i]] - 1);
      } else {
        ans[i] = -2;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    if (ans[i] == -1) {
      cout << "YES\n";
    } else if (ans[i] == -2) {
      cout << "NO\n";
    } else {
      cout << "CAN " << ans[i] << "\n";
    }
  }
}
