#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <class T>
typename T::value_type arr_sum(const T &v, int n) {
  typename T::value_type sum = 0;
  for (int i = (0); i < (n); ++i) sum += v[i];
  return sum;
}
struct Sync_stdio {
  Sync_stdio() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
  }
} _sync_stdio;
struct Z {
  int a;
  long long w;
  int operator<(const Z &a) const { return w > a.w; };
};
struct Y {
  int a;
  int b;
  long long w;
};
vector<vector<Z>> gout;
vector<vector<Z>> gin;
vector<long long> d1;
vector<long long> d2;
void dijkstra(int x, const vector<vector<Z>> &g, vector<long long> &d) {
  priority_queue<Z> pq;
  pq.push({x, 0});
  while (pq.size()) {
    Z t = pq.top();
    pq.pop();
    if (t.w != d[t.a]) {
      continue;
    }
    for (auto i : g[t.a]) {
      if (d[t.a] + i.w < d[i.a]) {
        d[i.a] = d[t.a] + i.w;
        pq.push({i.a, d[i.a]});
      }
    }
  }
}
vector<vector<pair<int, int>>> g;
vector<int> used;
vector<int> tin;
vector<int> fup;
set<int> bridges;
int timer = 0;
void dfs(int t, int p = -1) {
  used[t] = 1;
  tin[t] = fup[t] = timer++;
  for (auto i : g[t]) {
    if (i.second == p) {
      continue;
    }
    if (used[i.first]) {
      fup[t] = min(fup[t], tin[i.first]);
    } else {
      dfs(i.first, i.second);
      fup[t] = min(fup[t], fup[i.first]);
      if (fup[i.first] > tin[t]) {
        bridges.insert(i.second);
      }
    }
  }
}
void find_bridges() {
  timer = 0;
  used.assign(g.size(), 0);
  tin.resize(g.size());
  fup.resize(g.size());
  for (int i = (0); i < (g.size()); ++i) {
    if (!used[i]) {
      dfs(i);
    }
  }
}
int main() {
  int n, m, x, t;
  cin >> n >> m >> x >> t;
  --x;
  --t;
  d1.assign(n, LLONG_MAX);
  d2.assign(n, LLONG_MAX);
  gout.resize(n);
  gin.resize(n);
  g.resize(n);
  vector<Y> v(m);
  for (int i = (0); i < (m); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    gout[a].push_back({b, c});
    gin[b].push_back({a, c});
    v[i] = {a, b, c};
  }
  d1[x] = 0;
  d2[t] = 0;
  dijkstra(x, gout, d1);
  dijkstra(t, gin, d2);
  vector<int> cc(m);
  for (int i = (0); i < (m); ++i) {
    if (d1[v[i].a] + d2[v[i].b] + v[i].w == d1[t]) {
      cc[i] = 1;
      g[v[i].a].push_back({v[i].b, i});
      g[v[i].b].push_back({v[i].a, i});
      continue;
    }
  }
  find_bridges();
  for (int i = (0); i < (m); ++i) {
    if (cc[i] == 1 && bridges.find(i) != bridges.end()) {
      cout << "YES"
           << "\n";
      continue;
    }
    if (d1[v[i].a] == LLONG_MAX || d2[v[i].b] == LLONG_MAX ||
        d1[v[i].a] + d2[v[i].b] + 1 >= d1[t] ||
        d1[v[i].a] + d2[v[i].b] + v[i].w - d1[t] + 1 <= 0) {
      cout << "NO"
           << "\n";
      continue;
    }
    cout << "CAN " << d1[v[i].a] + d2[v[i].b] + v[i].w - d1[t] + 1 << "\n";
  }
}
