#include <bits/stdc++.h>
using namespace std;
long long inf = 1e18;
int main() {
  int n, m, s, t;
  scanf("%d %d %d %d", &n, &m, &s, &t);
  s--;
  t--;
  vector<vector<pair<int, int> > > adj_list(n);
  vector<vector<pair<int, int> > > adj_list_reversed(n);
  vector<vector<int> > number(n);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    a--;
    b--;
    number[a].push_back(i);
    adj_list[a].push_back(make_pair(c, b));
    adj_list_reversed[b].push_back(make_pair(c, a));
  }
  vector<long long> dist_from_s(n, inf);
  vector<long long> dist_to_t(n, inf);
  dist_from_s[s] = 0;
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      pq;
  pq.push(make_pair(0, s));
  while (!pq.empty()) {
    pair<long long, int> p = pq.top();
    pq.pop();
    if (p.first > dist_from_s[p.second]) {
      continue;
    }
    long long current_weight = p.first;
    int current_node = p.second;
    for (int i = 0; i < adj_list[current_node].size(); i++) {
      long long edge_weight = adj_list[current_node][i].first;
      int to = adj_list[current_node][i].second;
      if (dist_from_s[to] > current_weight + edge_weight) {
        dist_from_s[to] = current_weight + edge_weight;
        pq.push(make_pair(current_weight + edge_weight, to));
      }
    }
  }
  dist_to_t[t] = 0;
  pq.push(make_pair(0, t));
  while (!pq.empty()) {
    pair<long long, int> p = pq.top();
    pq.pop();
    if (p.first > dist_to_t[p.second]) {
      continue;
    }
    long long current_weight = p.first;
    int current_node = p.second;
    for (int i = 0; i < adj_list_reversed[current_node].size(); i++) {
      long long edge_weight = adj_list_reversed[current_node][i].first;
      int to = adj_list_reversed[current_node][i].second;
      if (dist_to_t[to] > current_weight + edge_weight) {
        dist_to_t[to] = current_weight + edge_weight;
        pq.push(make_pair(current_weight + edge_weight, to));
      }
    }
  }
  vector<int> answer(m, 0);
  map<long long, pair<int, int> > start_finish;
  map<long long, vector<int> > start;
  map<long long, vector<int> > finish;
  long long best = dist_from_s[t];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < adj_list[i].size(); j++) {
      long long weight = adj_list[i][j].first;
      int node1 = i;
      int node2 = adj_list[i][j].second;
      if (dist_from_s[node1] + weight + dist_to_t[node2] == best) {
        start[dist_from_s[node1]].push_back(number[i][j]);
        start_finish[dist_from_s[node1]].first++;
        finish[dist_from_s[node1] + weight].push_back(number[i][j]);
        start_finish[dist_from_s[node1] + weight].second++;
      } else {
        answer[number[i][j]] = 1;
      }
    }
  }
  int opened = 0;
  for (map<long long, pair<int, int> >::iterator it = start_finish.begin();
       it != start_finish.end(); it++) {
    long long weight = it->first;
    pair<int, int> p = it->second;
    opened += p.first;
    opened -= p.second;
    if (opened > 1) {
      for (int i = 0; i < start[weight].size(); i++) {
        answer[start[weight][i]] = 1;
      }
    }
  }
  vector<long long> how_much(m, -1);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < adj_list[i].size(); j++) {
      if (answer[number[i][j]] == 0) {
        continue;
      }
      long long weight = adj_list[i][j].first;
      int node1 = i;
      int node2 = adj_list[i][j].second;
      long long verlagen =
          dist_from_s[node1] + weight + dist_to_t[node2] - best + 1;
      if (weight - verlagen >= 1) {
        how_much[number[i][j]] = verlagen;
      } else {
        answer[number[i][j]] = 2;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    if (answer[i] == 0) {
      printf("YES\n");
    } else if (answer[i] == 1) {
      printf("CAN %I64d\n", how_much[i]);
    } else {
      printf("NO\n");
    }
  }
  return 0;
}
