#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long BIG = 1446803456761533460LL;
const int Big = 336860180;
const long long int INF = LONG_LONG_MAX;
const vector<vector<long long int> > adj4({{0, 1}, {0, -1}, {1, 0}, {-1, 0}});
const vector<vector<long long int> > adj8(
    {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {-1, -1}, {1, -1}, {-1, 1}, {1, 1}});
long long int gcd(long long int a, long long int b) {
  return b == 0 ? a : gcd(b, a % b);
}
bool isprime(long long int n) {
  if (n == 2 || n == 3) return true;
  if (n < 2 || n % 2 == 0 || n % 3 == 0) return false;
  for (long long int i = 6; (i - 1) * (i - 1) <= n; i += 6) {
    if (n % (i - 1) == 0 || n % (i + 1) == 0) {
      return false;
    }
  }
  return true;
}
vector<bool> sprime;
void genPrime(long long int sz) {
  sprime = vector<bool>(sz, true);
  sprime[0] = false;
  sprime[1] = false;
  for (long long int i = (2); i < (sz); ++i) {
    if (sprime[i]) {
      for (long long int j = i * i; j < sz; j += i) {
        sprime[j] = false;
      }
    }
  }
}
long long int powMod(long long int a, long long int b, long long int mod) {
  long long int n = 1;
  long long int p = a;
  while (b > 0) {
    if (b % 2 == 1) {
      n *= p;
      n %= mod;
    }
    p *= p;
    p %= mod;
    b /= 2;
  }
  return n;
}
long long int modularInverse(long long int a, long long int mod) {
  return powMod(a, mod - 2, mod);
}
long long int binarysearch(long long int l, long long int r,
                           bool (*bsfunction)(long long int)) {
  while (r - l > 1) {
    long long int mid = (l + r) / 2;
    bool val = bsfunction(mid);
    if (val) {
      r = mid;
    } else {
      l = mid;
    }
  }
  return l;
}
stringstream sss;
const long long int maxn = 100010;
vector<pair<long long int, long long int> > g[maxn];
vector<pair<long long int, long long int> > g2[maxn];
long long int ds[maxn];
long long int dt[maxn];
long long int es[maxn][3];
long long int tree[maxn];
long long int bridge[maxn];
long long int vt[maxn];
long long int vt2[maxn];
void dfs(long long int step, long long int par) {
  for (auto x : g[step]) {
    if (tree[x.second] == 0 || x.second == par) continue;
    long long int v = x.first;
    if (vt[v] == 0) {
      vt[v] = vt[step] + 1;
      vt2[v] = vt[step] + 1;
      dfs(v, x.second);
      vt2[step] = min(vt2[step], (vt2[v]));
      if (vt2[v] <= vt[step]) {
        bridge[x.second] = 1;
      }
    } else {
      bridge[x.second] = 1;
      vt2[step] = min(vt2[step], (vt[v]));
    }
  }
  for (auto x : g2[step]) {
    if (tree[x.second] == 0 || x.second == par) continue;
    long long int v = x.first;
    if (vt[v] == 0) {
      vt[v] = vt[step] + 1;
      vt2[v] = vt[step] + 1;
      dfs(v, x.second);
      vt2[step] = min(vt2[step], (vt2[v]));
      if (vt2[v] <= vt[step]) {
        bridge[x.second] = 1;
      }
    } else {
      bridge[x.second] = 1;
      vt2[step] = min(vt2[step], (vt[v]));
    }
  }
}
void MAIN() {
  long long int n, m, s, t;
  cin >> n >> m >> s >> t;
  --s, --t;
  for (long long int i = 0; i < (m); ++i) {
    long long int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    g[a].push_back(make_pair(b, i));
    g2[b].push_back(make_pair(a, i));
    es[i][0] = a;
    es[i][1] = b;
    es[i][2] = c;
  }
  memset(ds, 20, sizeof ds);
  set<pair<long long int, long long int> > st;
  ds[s] = 0;
  st.insert(make_pair(ds[s], s));
  while (!st.empty()) {
    long long int x = st.begin()->second;
    st.erase(st.begin());
    for (auto y : g[x]) {
      long long int v = y.first;
      long long int w = es[y.second][2];
      if (ds[x] + w < ds[v]) {
        st.erase(make_pair(ds[v], v));
        ds[v] = ds[x] + w;
        st.insert(make_pair(ds[v], v));
      }
    }
  }
  memset(dt, 20, sizeof dt);
  st.clear();
  dt[t] = 0;
  st.insert(make_pair(dt[t], t));
  while (!st.empty()) {
    long long int x = st.begin()->second;
    st.erase(st.begin());
    for (auto y : g2[x]) {
      long long int v = y.first;
      long long int w = es[y.second][2];
      if (dt[x] + w <= dt[v]) {
        st.erase(make_pair(dt[v], v));
        dt[v] = dt[x] + w;
        st.insert(make_pair(dt[v], v));
      }
    }
  }
  long long int mn = ds[t];
  for (long long int i = 0; i < (m); ++i) {
    long long int a = es[i][0];
    long long int b = es[i][1];
    long long int c = es[i][2];
    long long int d = ds[a] + dt[b] + c;
    tree[i] = d == mn;
  }
  dfs(s, -1);
  for (long long int i = 0; i < (m); ++i) {
    long long int a = es[i][0];
    long long int b = es[i][1];
    long long int c = es[i][2];
    long long int d = ds[a] + dt[b] + c;
    if (tree[i] == 1 && bridge[i] == 0) {
      cout << ("YES") << endl;
    } else if (d - c + 1 >= mn) {
      cout << ("NO") << endl;
    } else {
      cout << "CAN " << d - mn + 1 << endl;
    }
  }
}
const long long int TESTCASEN = 1;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  sss << R"(
3 4 1 3
1 2 2
1 2 1
2 3 1
2 3 1
6 7 1 6
1 2 2
1 3 10
2 3 7
2 4 8
3 5 3
4 5 2
5 6 1
3 3 1 3
1 2 10
2 3 10
1 3 100
2 2 1 2
1 2 1
1 2 2
    )";
  for (long long int i = 0; i < (TESTCASEN); ++i) {
    MAIN();
  }
  return 0;
}
