#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#define INF 0x3f3f3f3f

using namespace std;
const long long maxn = 1e5+10;
const long long mod = 1e9+13;

struct edge{
    long long v,to,cost;
    edge(long long t,long long c):to(t),cost(c){};
    edge(long long v, long long t,long long c):v(v),to(t),cost(c){};
    bool operator < (const edge & a) const{
        return cost > a.cost;
    }
};

vector <edge> G_a[maxn];
vector <edge> G_b[maxn];
vector <edge> e;

void addedge(long long from, long long to, long long cost){
    G_a[from].push_back(edge(to, cost));
    G_b[to].push_back(edge(from, cost));
}
long long dis_a[maxn];
long long dis_b[maxn];
long long cnt_a[maxn];
long long cnt_b[maxn];
long long n;

void Dijkstra(long long s,long long cnt[], long long dis[],bool flag){
    for (long long i = 0 ; i <= n ; i ++){
        dis[i] = INF;cnt[i] = 0;
    }
    dis[s] = 0;cnt[s] = 1;
    priority_queue<edge> Q;
    Q.push(edge(s,dis[s]));
    while(!Q.empty()){
        edge tmp = Q.top();Q.pop();
        int limt = flag?G_a[tmp.to].size():G_b[tmp.to].size();
        for(long long i = 0 ; i < limt; i ++){
            edge& next = flag ? G_a[tmp.to][i]:G_b[tmp.to][i];
            if(dis[next.to] == tmp.cost+next.cost)
                cnt[next.to] = (cnt[tmp.to]+cnt[next.to])%mod;
            if(dis[next.to] > tmp.cost + next.cost){
                cnt[next.to] = cnt[tmp.to];
                dis[next.to] = tmp.cost + next.cost;
                Q.push(edge(next.to,dis[next.to]));
            }
        }
    }
}

int main(){
    long long m,s,t;
    cin >>n>>m>>s>>t;
    long long from, to, cos;
    for (long long i = 0 ; i < m ; i ++){
        scanf("%I64d %I64d %I64d",&from,&to,&cos);
        addedge(from,to,cos);
        e.push_back(edge(from,to,cos));
    }
    Dijkstra(s,cnt_a,dis_a,true);
    Dijkstra(t,cnt_b,dis_b,false);
    for(long long i = 0 ; i < m ; i ++){

        if(dis_a[e[i].v]+e[i].cost+dis_b[e[i].to] == dis_a[t] && (cnt_a[e[i].v]*cnt_b[e[i].to])%mod == cnt_a[t])
            puts("YES");
        else{
            long long ect = dis_a[t]-dis_a[e[i].v]-dis_b[e[i].to]-1;
            if(ect < 1 || e[i].cost == 1)
                puts("NO");
            else printf ("CAN %I64d\n",e[i].cost-ect);
        }
    }
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#define INF 0x3f3f3f3f3f3f3f3f
typedef long long ll;

using namespace std;
const ll maxn = 1e5+10;
const ll mod = 1e9+13;

struct edge{
    ll v,to,cost;
    edge(ll t,ll c):to(t),cost(c){};
    edge(ll v, ll t,ll c):v(v),to(t),cost(c){};
    bool operator < (const edge & a) const{
        return cost > a.cost;
    }
};

vector <edge> G_a[maxn];
vector <edge> G_b[maxn];
vector <edge> e;

void addedge(ll from, ll to, ll cost){
    G_a[from].push_back(edge(to, cost));
    G_b[to].push_back(edge(from, cost));
}
ll dis_a[maxn];
ll dis_b[maxn];
ll cnt_a[maxn];
ll cnt_b[maxn];
ll n;

void Dijkstra(ll s,ll cnt[], ll dis[],bool flag){
    for (ll i = 0 ; i <= n ; i ++){
        dis[i] = INF;cnt[i] = 0;
    }
    dis[s] = 0;cnt[s] = 1;
    priority_queue<edge> Q;
    Q.push(edge(s,dis[s]));
    while(!Q.empty()){
        edge tmp = Q.top();Q.pop();
        ll limt = flag?G_a[tmp.to].size():G_b[tmp.to].size();
        for(ll i = 0 ; i < limt; i ++){
            edge& next = flag ? G_a[tmp.to][i]:G_b[tmp.to][i];
            if(dis[next.to] == tmp.cost+next.cost)
                cnt[next.to] = (cnt[tmp.to]+cnt[next.to])%mod;
            if(dis[next.to] > tmp.cost + next.cost){
                cnt[next.to] = cnt[tmp.to];
                dis[next.to] = tmp.cost + next.cost;
                Q.push(edge(next.to,dis[next.to]));
            }
        }
    }
}

int main(){
    ll m,s,t;
    cin >>n>>m>>s>>t;
    ll from, to, cos;
    for (ll i = 0 ; i < m ; i ++){
        scanf("%I64d %I64d %I64d",&from,&to,&cos);
        addedge(from,to,cos);
        e.push_back(edge(from,to,cos));
    }
    Dijkstra(s,cnt_a,dis_a,true);
    Dijkstra(t,cnt_b,dis_b,false);
    for(ll i = 0 ; i < m ; i ++){

        if(dis_a[e[i].v]+e[i].cost+dis_b[e[i].to] == dis_a[t] && (cnt_a[e[i].v]*cnt_b[e[i].to])%mod == cnt_a[t])
            puts("YES");
        else{
            ll ect = dis_a[t]-dis_a[e[i].v]-dis_b[e[i].to]-1;
            if(ect < 1 || e[i].cost == 1)
                puts("NO");
            else printf ("CAN %I64d\n",e[i].cost-ect);
        }
    }
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#define INF 0xfffffffff

using namespace std;
const long long maxn = 1e5+10;
const long long mod = 1e9+13;

struct edge{
    long long v,to,cost;
    edge(long long t,long long c):to(t),cost(c){};
    edge(long long v, long long t,long long c):v(v),to(t),cost(c){};
    bool operator < (const edge & a) const{
        return cost > a.cost;
    }
};

vector <edge> G_a[maxn];
vector <edge> G_b[maxn];
vector <edge> e;

void addedge(long long from, long long to, long long cost){
    G_a[from].push_back(edge(to, cost));
    G_b[to].push_back(edge(from, cost));
}
long long dis_a[maxn];
long long dis_b[maxn];
long long cnt_a[maxn];
long long cnt_b[maxn];
long long n;

void Dijkstra(long long s,long long cnt[], long long dis[],bool flag){
    for (long long i = 0 ; i <= n ; i ++){
        dis[i] = INF;cnt[i] = 0;
    }
    dis[s] = 0;cnt[s] = 1;
    priority_queue<edge> Q;
    Q.push(edge(s,dis[s]));
    while(!Q.empty()){
        edge tmp = Q.top();Q.pop();
        int limt = flag?G_a[tmp.to].size():G_b[tmp.to].size();
        for(long long i = 0 ; i < limt; i ++){
            edge& next = flag ? G_a[tmp.to][i]:G_b[tmp.to][i];
            if(dis[next.to] == tmp.cost+next.cost)
                cnt[next.to] = (cnt[tmp.to]+cnt[next.to])%mod;
            if(dis[next.to] > tmp.cost + next.cost){
                cnt[next.to] = cnt[tmp.to];
                dis[next.to] = tmp.cost + next.cost;
                Q.push(edge(next.to,dis[next.to]));
            }
        }
    }
}

int main(){
    long long m,s,t;
    cin >>n>>m>>s>>t;
    long long from, to, cos;
    for (long long i = 0 ; i < m ; i ++){
        scanf("%I64d %I64d %I64d",&from,&to,&cos);
        addedge(from,to,cos);
        e.push_back(edge(from,to,cos));
    }
    Dijkstra(s,cnt_a,dis_a,true);
    Dijkstra(t,cnt_b,dis_b,false);
    for(long long i = 0 ; i < m ; i ++){

        if(dis_a[e[i].v]+e[i].cost+dis_b[e[i].to] == dis_a[t] && (cnt_a[e[i].v]*cnt_b[e[i].to])%mod == cnt_a[t])
            puts("YES");
        else{
            long long ect = dis_a[t]-dis_a[e[i].v]-dis_b[e[i].to]-1;
            if(ect < 1 || e[i].cost == 1)
                puts("NO");
            else printf ("CAN %I64d\n",e[i].cost-ect);
        }
    }
}


#include <bits/stdc++.h>

#define MAX 100010
using namespace std;

typedef pair<long long,int> ii;
const long long INF = 10000000000110LL;
int n,m,s,t,a,b,l;

struct edge
{
    int x,y,peso;
    edge(int xx, int yy, int pesoo)
    {
        x = xx;
        y = yy;
        peso = pesoo;
    }

    bool operator < (edge a) const
    {
        if (x == a.x)
        {
            if (y == a.y)
            {
                return peso < a.peso;
            }
            return y < a.y;
        }
        return x < a.x;
    }
};

vector<int> adj[MAX], w[MAX], revadj[MAX], revw[MAX], spadj[MAX], spw[MAX];
set< edge > S;
long long dis[MAX];
long long revdis[MAX];
vector<edge> edges;
int dfsnum[MAX];
int dfslow[MAX];
int num;
map<edge, int>  cnt;

void pontes(int p, int l)
{
    dfsnum[p] = dfslow[p] = num++;

    for (int i = 0; i < spadj[p].size(); ++i)
    {
        int v = spadj[p][i];
        int peso = spw[p][i];

        if (v == l) continue;
        if (dfsnum[v] == 0)
        {
            pontes(v, p);
            if (dfslow[v] > dfsnum[p])
            {
                edge tmp1(p, v, peso);
                edge tmp2(v, p, peso);
                S.insert(tmp1);
                S.insert(tmp2);
            }
            dfslow[p] = min(dfslow[p], dfslow[v]);
        }
        else
        {
            dfslow[p] = min(dfslow[p], dfsnum[v]);
        }
    }
}

void dijkstra(long long dis[MAX], vector<int> adj[MAX], vector<int> w[MAX], int s, int t)
{
    for (int i = 0; i < MAX; ++i)
    {
        dis[i] = INF;
    }

    priority_queue<ii, vector<ii>, greater<ii> > pq;

    dis[s] = 0;
    pq.push(make_pair(dis[s],s));

    while (!pq.empty())
    {
        long long peso = pq.top().first;
        int v = pq.top().second;
        pq.pop();

        if (peso != dis[v])
        {
            continue;
        }

        for (int i = 0; i < adj[v].size(); ++i)
        {
            int u = adj[v][i];
            long long pesot = w[v][i];
            if (dis[u] > dis[v] + pesot)
            {
                dis[u] = dis[v] + pesot;
                pq.push(make_pair(dis[u], u));
            }
        }
    }

}

int main(void)
{
    cin >> n >> m >> s >> t;

    for (int i = 0; i < m; ++i)
    {
        cin >> a >> b >> l;

        adj[a].push_back(b);
        w[a].push_back(l);
        revadj[b].push_back(a);
        revw[b].push_back(l);

        edge tmp(a,b,l);
        edges.push_back(tmp);
        cnt[tmp]++;

    }

    dijkstra(dis, adj, w, s, t);
    dijkstra(revdis, revadj, revw, t, s);

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;

        if (dis[v] == INF || dis[u] == INF)
            continue;
        if (revdis[v] == INF || revdis[u] == INF)
            continue;

        if (dis[v] + revdis[u] + (long long)peso == dis[t])
        {
            spadj[v].push_back(u);
            spw[v].push_back(peso);
            spadj[u].push_back(v);
            spw[u].push_back(peso);
        }
    }

    num = 1;

    for (int i = 1; i <= n; ++i)
    {
        if (dfsnum[i] == 0)
            pontes(i, i);
    }

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;

        if (S.count(edges[i]) && cnt[edges[i]] == 1)
        {
            cout << "YES\n";
        }
        else
        {
            long long dist = 0;
            edge tmp(v, u, peso);
            if (cnt[tmp] > 0 && dis[v] < INF && revdis[u] < INF)
                dist = dis[v] + revdis[u] + (long long)peso;
            else
                continue;

            long long offset = llabs(dis[t] - dist) + 1;
            if (offset >= (long long)peso || dis[t] >= INF)
            {
                cout << "NO\n";
            }
            else
            {
                cout << "CAN " << offset << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define MAX 100010
using namespace std;

typedef pair<long long,int> ii;

int n,m,s,t,a,b,l;

struct edge
{
    int x,y,peso;
    edge(int xx, int yy, int pesoo)
    {
        x = xx;
        y = yy;
        peso = pesoo;
    }

    bool operator < (edge a) const
    {
        if (x == a.x)
        {
            if (y == a.y)
            {
                return peso < a.peso;
            }
            return y < a.y;
        }
        return x < a.x;
    }
};

vector<int> adj[MAX], w[MAX], revadj[MAX], revw[MAX], spadj[MAX], spw[MAX];
set< edge > S;
long long dis[MAX];
long long revdis[MAX];
vector<edge> edges;
int dfsnum[MAX];
int dfslow[MAX];
int num;

void pontes(int p, int l)
{
    dfsnum[p] = dfslow[p] = num++;

    for (int i = 0; i < spadj[p].size(); ++i)
    {
        int v = spadj[p][i];
        int peso = spw[p][i];

        if (v == l) continue;
        if (dfsnum[v] == 0)
        {
            pontes(v, p);
            if (dfslow[v] > dfsnum[p])
            {
                edge tmp1(p, v, peso);
                edge tmp2(v, p, peso);

                S.insert(tmp1);
                S.insert(tmp2);
            }
            dfslow[p] = min(dfslow[p], dfslow[v]);
        }
        else
        {
            dfslow[p] = min(dfslow[p], dfsnum[v]);
        }
    }
}

void dijkstra(long long dis[MAX], vector<int> adj[MAX], vector<int> w[MAX], int s, int t)
{
    for (int i = 0; i < MAX; ++i)
    {
        dis[i] = 1000000000110LL;
    }

    priority_queue<ii, vector<ii>, greater<ii> > pq;

    dis[s] = 0;
    pq.push(make_pair(dis[s],s));

    while (!pq.empty())
    {
        long long peso = pq.top().first;
        int v = pq.top().second;
        pq.pop();

        if (peso != dis[v])
        {
            continue;
        }

        if (v == t)
        {
            return;
        }
        for (int i = 0; i < adj[v].size(); ++i)
        {
            int u = adj[v][i];
            long long pesot = w[v][i];
            if (dis[u] > dis[v] + pesot)
            {
                dis[u] = dis[v] + pesot;
                pq.push(make_pair(dis[u], u));
            }
        }
    }

}

int main(void)
{
    cin >> n >> m >> s >> t;

    for (int i = 0; i < m; ++i)
    {
        cin >> a >> b >> l;
        adj[a].push_back(b);
        w[a].push_back(l);
        revadj[b].push_back(a);
        revw[b].push_back(l);
        edge tmp(a,b,l);
        edges.push_back(tmp);
    }

    dijkstra(dis, adj, w, s, t);
    dijkstra(revdis, revadj, revw, t, s);

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;

        if (dis[v] + revdis[u] + (long long)peso == dis[t] || revdis[v] + dis[u] + (long long)peso == dis[t])
        {
            spadj[v].push_back(u);
            spw[v].push_back(peso);
            spadj[u].push_back(v);
            spw[u].push_back(peso);
        }
    }

    num = 1;

    for (int i = 1; i <= n; ++i)
    {
        if (dfsnum[i] == 0)
            pontes(i, i);
    }

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;
        if (dis[v] + revdis[u] + (long long)peso == dis[t] || revdis[v] + dis[u] + (long long)peso == dis[t] && S.count(edges[i]))
        {
            cout << "YES\n";
        }
        else
        {
            long long dist = min(dis[v] + revdis[u] + peso, dis[u] + revdis[v] + peso);
            long long offset = abs(dis[t] - dist) + 1;
            if (offset >= peso)
            {
                cout << "NO\n";
            }
            else
            {
                cout << "CAN " << offset << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define MAX 100010
using namespace std;

typedef pair<long long,int> ii;

int n,m,s,t,a,b,l;

struct edge
{
    int x,y,peso;
    edge(int xx, int yy, int pesoo)
    {
        x = xx;
        y = yy;
        peso = pesoo;
    }

    bool operator < (edge a) const
    {
        if (x == a.x)
        {
            if (y == a.y)
            {
                return peso < a.peso;
            }
            return y < a.y;
        }
        return x < a.x;
    }
};

vector<int> adj[MAX], w[MAX], revadj[MAX], revw[MAX], spadj[MAX], spw[MAX];
set< edge > S;
long long dis[MAX];
long long revdis[MAX];
vector<edge> edges;
int dfsnum[MAX];
int dfslow[MAX];
int num;

void pontes(int p, int l)
{
    dfsnum[p] = dfslow[p] = num++;

    for (int i = 0; i < spadj[p].size(); ++i)
    {
        int v = spadj[p][i];
        int peso = spw[p][i];

        if (v == l) continue;
        if (dfsnum[v] == 0)
        {
            pontes(v, p);
            if (dfslow[v] > dfsnum[p])
            {
                edge tmp1(p, v, peso);
                edge tmp2(v, p, peso);

                S.insert(tmp1);
                S.insert(tmp2);
            }
            dfslow[p] = min(dfslow[p], dfslow[v]);
        }
        else
        {
            dfslow[p] = min(dfslow[p], dfsnum[v]);
        }
    }
}

void dijkstra(long long dis[MAX], vector<int> adj[MAX], vector<int> w[MAX], int s, int t)
{
    for (int i = 0; i < MAX; ++i)
    {
        dis[i] = 1000000000110LL;
    }

    priority_queue<ii, vector<ii>, greater<ii> > pq;

    dis[s] = 0;
    pq.push(make_pair(dis[s],s));

    while (!pq.empty())
    {
        long long peso = pq.top().first;
        int v = pq.top().second;
        pq.pop();

        if (peso != dis[v])
        {
            continue;
        }

        if (v == t)
        {
            return;
        }
        for (int i = 0; i < adj[v].size(); ++i)
        {
            int u = adj[v][i];
            long long pesot = w[v][i];
            if (dis[u] > dis[v] + pesot)
            {
                dis[u] = dis[v] + pesot;
                pq.push(make_pair(dis[u], u));
            }
        }
    }

}

int main(void)
{
    cin >> n >> m >> s >> t;

    for (int i = 0; i < m; ++i)
    {
        cin >> a >> b >> l;
        adj[a].push_back(b);
        w[a].push_back(l);
        revadj[b].push_back(a);
        revw[b].push_back(l);
        edge tmp(a,b,l);
        edges.push_back(tmp);
    }

    dijkstra(dis, adj, w, s, t);
    dijkstra(revdis, revadj, revw, t, s);

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;

        if (dis[v] + revdis[u] + peso == dis[t] || revdis[v] + dis[u] + peso == dis[t])
        {
            spadj[v].push_back(u);
            spw[v].push_back(peso);
            spadj[u].push_back(v);
            spw[u].push_back(peso);
        }
    }

    num = 1;

    for (int i = 1; i <= n; ++i)
    {
        if (dfsnum[i] == 0)
            pontes(i, i);
    }

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;
        if (S.count(edges[i]))
        {
            cout << "YES\n";
        }
        else
        {
            long long dist = min(dis[v] + revdis[u] + peso, dis[u] + revdis[v] + peso);
            long long offset = abs(dis[t] - dist) + 1;
            if (offset >= peso)
            {
                cout << "NO\n";
            }
            else
            {
                cout << "CAN " << offset << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define MAX 100010
using namespace std;

typedef pair<long long,int> ii;

int n,m,s,t,a,b,l;

struct edge
{
    int x,y,peso;
    edge(int xx, int yy, int pesoo)
    {
        x = xx;
        y = yy;
        peso = pesoo;
    }

    bool operator < (edge a) const
    {
        if (x == a.x)
        {
            if (y == a.y)
            {
                return peso < a.peso;
            }
            return y < a.y;
        }
        return x < a.x;
    }
};

vector<int> adj[MAX], w[MAX], revadj[MAX], revw[MAX], spadj[MAX], spw[MAX];
set< edge > S;
long long dis[MAX];
long long revdis[MAX];
vector<edge> edges;
int dfsnum[MAX];
int dfslow[MAX];
int num;
map<edge, int>  cnt;

void pontes(int p, int l)
{
    dfsnum[p] = dfslow[p] = num++;

    for (int i = 0; i < spadj[p].size(); ++i)
    {
        int v = spadj[p][i];
        int peso = spw[p][i];

        if (v == l) continue;
        if (dfsnum[v] == 0)
        {
            pontes(v, p);
            edge tmp1(p, v, peso);
            edge tmp2(v, p, peso);
            if (dfslow[v] > dfsnum[p] && cnt[tmp1] <= 1 && cnt[tmp2] <= 1)
            {
                S.insert(tmp1);
                S.insert(tmp2);
            }
            dfslow[p] = min(dfslow[p], dfslow[v]);
        }
        else
        {
            dfslow[p] = min(dfslow[p], dfsnum[v]);
        }
    }
}

void dijkstra(long long dis[MAX], vector<int> adj[MAX], vector<int> w[MAX], int s, int t)
{
    for (int i = 0; i < MAX; ++i)
    {
        dis[i] = 1000000000110LL;
    }

    priority_queue<ii, vector<ii>, greater<ii> > pq;

    dis[s] = 0;
    pq.push(make_pair(dis[s],s));

    while (!pq.empty())
    {
        long long peso = pq.top().first;
        int v = pq.top().second;
        pq.pop();

        if (peso != dis[v])
        {
            continue;
        }

        if (v == t)
        {
            return;
        }
        for (int i = 0; i < adj[v].size(); ++i)
        {
            int u = adj[v][i];
            long long pesot = w[v][i];
            if (dis[u] > dis[v] + pesot)
            {
                dis[u] = dis[v] + pesot;
                pq.push(make_pair(dis[u], u));
            }
        }
    }

}

int main(void)
{
    cin >> n >> m >> s >> t;

    for (int i = 0; i < m; ++i)
    {
        cin >> a >> b >> l;
        adj[a].push_back(b);
        w[a].push_back(l);
        revadj[b].push_back(a);
        revw[b].push_back(l);
        edge tmp(a,b,l);
        edges.push_back(tmp);
        cnt[tmp]++;
    }

    dijkstra(dis, adj, w, s, t);
    dijkstra(revdis, revadj, revw, t, s);

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;

        if (dis[v] + revdis[u] + (long long)peso == dis[t] || revdis[v] + dis[u] + (long long)peso == dis[t])
        {
            spadj[v].push_back(u);
            spw[v].push_back(peso);
            spadj[u].push_back(v);
            spw[u].push_back(peso);
        }
    }

    num = 1;

    for (int i = 1; i <= n; ++i)
    {
        if (dfsnum[i] == 0)
            pontes(i, i);
    }

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;
        if ((dis[v] + revdis[u] + (long long)peso == dis[t] || revdis[v] + dis[u] + (long long)peso == dis[t]) && S.count(edges[i]))
        {
            cout << "YES\n";
        }
        else
        {
            long long dist = min(dis[v] + revdis[u] + peso, dis[u] + revdis[v] + peso);
            long long offset = abs(dis[t] - dist) + 1;
            if (offset >= peso)
            {
                cout << "NO\n";
            }
            else
            {
                cout << "CAN " << offset << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define MAX 100010
using namespace std;

typedef pair<long long,int> ii;
const long long INF	= 1000000000110LL;
int n,m,s,t,a,b,l;

struct edge
{
	int x,y,peso;
	edge(int xx, int yy, int pesoo)
	{
		x = xx;
		y = yy;
		peso = pesoo;
	}

	bool operator < (edge a) const
	{
		if (x == a.x)
		{
			if (y == a.y)
			{
				return peso < a.peso;
			}
			return y < a.y;
		}
		return x < a.x;
	}
};

vector<int> adj[MAX], w[MAX], revadj[MAX], revw[MAX], spadj[MAX], spw[MAX];
set< edge > S;
long long dis[MAX];
long long revdis[MAX];
vector<edge> edges;
int dfsnum[MAX];
int dfslow[MAX];
int num;
map<edge, int>  cnt;

void pontes(int p, int l)
{
	dfsnum[p] = dfslow[p] = num++;

	for (int i = 0; i < spadj[p].size(); ++i)
	{
		int v = spadj[p][i];
		int peso = spw[p][i];

		if (v == l) continue;
		if (dfsnum[v] == 0)
		{
			pontes(v, p);
			edge tmp1(p, v, peso);
			edge tmp2(v, p, peso);
			if (dfslow[v] > dfsnum[p])
			{
				if (cnt[tmp1] <= 1)
					S.insert(tmp1);
				if (cnt[tmp2] <= 1)
					S.insert(tmp2);
			}
			dfslow[p] = min(dfslow[p], dfslow[v]);
		}
		else
		{
			dfslow[p] = min(dfslow[p], dfsnum[v]);
		}
	}
}

void dijkstra(long long dis[MAX], vector<int> adj[MAX], vector<int> w[MAX], int s, int t)
{
	for (int i = 0; i < MAX; ++i)
	{
		dis[i] = INF;
	}

	priority_queue<ii, vector<ii>, greater<ii> > pq;

	dis[s] = 0;
	pq.push(make_pair(dis[s],s));

	while (!pq.empty())
	{
		long long peso = pq.top().first;
		int v = pq.top().second;
		pq.pop();

		if (peso != dis[v])
		{
			continue;
		}

		if (v == t)
		{
			return;
		}
		for (int i = 0; i < adj[v].size(); ++i)
		{
			int u = adj[v][i];
			long long pesot = w[v][i];
			if (dis[u] > dis[v] + pesot)
			{
				dis[u] = dis[v] + pesot;
				pq.push(make_pair(dis[u], u));
			}
		}
	}

}

int main(void)
{
	cin >> n >> m >> s >> t;

	for (int i = 0; i < m; ++i)
	{
		cin >> a >> b >> l;
		adj[a].push_back(b);
		w[a].push_back(l);
		revadj[b].push_back(a);
		revw[b].push_back(l);
		edge tmp(a,b,l);
		edges.push_back(tmp);
		cnt[tmp]++;
	}

	dijkstra(dis, adj, w, s, t);
	dijkstra(revdis, revadj, revw, t, s);

	for (int i = 0; i < edges.size(); ++i)
	{
		int v = edges[i].x;
		int u = edges[i].y;
		int peso = edges[i].peso;

		if (dis[v] + revdis[u] + (long long)peso == dis[t] || revdis[v] + dis[u] + (long long)peso == dis[t])
		{
			spadj[v].push_back(u);
			spw[v].push_back(peso);
			spadj[u].push_back(v);
			spw[u].push_back(peso);
		}
	}

	num = 1;

	for (int i = 1; i <= n; ++i)
	{
		if (dfsnum[i] == 0)
			pontes(i, i);
	}

	for (int i = 0; i < edges.size(); ++i)
	{
		int v = edges[i].x;
		int u = edges[i].y;
		int peso = edges[i].peso;
		if ((dis[v] + revdis[u] + (long long)peso == dis[t] || revdis[v] + dis[u] + (long long)peso == dis[t]) && S.count(edges[i]))
		{
			cout << "YES\n";
		}
		else
		{
			long long dist = 0;
			edge tmp(v, u, peso);
			if (cnt[tmp] > 0)
				dist = dis[v] + revdis[u] + (long long)peso;

			edge tmp1(u, v, peso);
			if (cnt[tmp1] > 0)
			  dist = min(dist, dis[u] + revdis[v] + (long long)peso);
			long long offset = llabs(dis[t] - dist) + 1;
			if (offset >= (long long)peso || dis[t] >= INF)
			{
				cout << "NO\n";
			}
			else
			{
				cout << "CAN " << offset << "\n";
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>

#define MAX 100010
using namespace std;

typedef pair<long long,int> ii;
const long long INF = 1000000000110LL;
int n,m,s,t,a,b,l;

struct edge
{
    int x,y,peso;
    edge(int xx, int yy, int pesoo)
    {
        x = xx;
        y = yy;
        peso = pesoo;
    }

    bool operator < (edge a) const
    {
        if (x == a.x)
        {
            if (y == a.y)
            {
                return peso < a.peso;
            }
            return y < a.y;
        }
        return x < a.x;
    }
};

vector<int> adj[MAX], w[MAX], revadj[MAX], revw[MAX], spadj[MAX], spw[MAX];
set< edge > S;
long long dis[MAX];
long long revdis[MAX];
vector<edge> edges;
int dfsnum[MAX];
int dfslow[MAX];
int num;
map<edge, int>  cnt;

void pontes(int p, int l)
{
    dfsnum[p] = dfslow[p] = num++;

    for (int i = 0; i < spadj[p].size(); ++i)
    {
        int v = spadj[p][i];
        int peso = spw[p][i];

        if (v == l) continue;
        if (dfsnum[v] == 0)
        {
            pontes(v, p);
            edge tmp1(p, v, peso);
            edge tmp2(v, p, peso);
            if (dfslow[v] > dfsnum[p] && cnt[tmp1] <= 1 && cnt[tmp2] <= 1)
            {
                S.insert(tmp1);
                S.insert(tmp2);
            }
            dfslow[p] = min(dfslow[p], dfslow[v]);
        }
        else
        {
            dfslow[p] = min(dfslow[p], dfsnum[v]);
        }
    }
}

void dijkstra(long long dis[MAX], vector<int> adj[MAX], vector<int> w[MAX], int s, int t)
{
    for (int i = 0; i < MAX; ++i)
    {
        dis[i] = INF;
    }

    priority_queue<ii, vector<ii>, greater<ii> > pq;

    dis[s] = 0;
    pq.push(make_pair(dis[s],s));

    while (!pq.empty())
    {
        long long peso = pq.top().first;
        int v = pq.top().second;
        pq.pop();

        if (peso != dis[v])
        {
            continue;
        }

        if (v == t)
        {
            return;
        }
        for (int i = 0; i < adj[v].size(); ++i)
        {
            int u = adj[v][i];
            long long pesot = w[v][i];
            if (dis[u] > dis[v] + pesot)
            {
                dis[u] = dis[v] + pesot;
                pq.push(make_pair(dis[u], u));
            }
        }
    }

}

int main(void)
{
    cin >> n >> m >> s >> t;

    for (int i = 0; i < m; ++i)
    {
        cin >> a >> b >> l;
        adj[a].push_back(b);
        w[a].push_back(l);
        revadj[b].push_back(a);
        revw[b].push_back(l);
        edge tmp(a,b,l);
        edges.push_back(tmp);
        cnt[tmp]++;
    }

    dijkstra(dis, adj, w, s, t);
    dijkstra(revdis, revadj, revw, t, s);

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;

        if (dis[v] + revdis[u] + (long long)peso == dis[t] || revdis[v] + dis[u] + (long long)peso == dis[t])
        {
            spadj[v].push_back(u);
            spw[v].push_back(peso);
            spadj[u].push_back(v);
            spw[u].push_back(peso);
        }
    }

    num = 1;

    for (int i = 1; i <= n; ++i)
    {
        if (dfsnum[i] == 0)
            pontes(i, i);
    }

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;
        if ((dis[v] + revdis[u] + (long long)peso == dis[t] || revdis[v] + dis[u] + (long long)peso == dis[t]) && S.count(edges[i]))
        {
            cout << "YES\n";
        }
        else
        {
            long long dist = min(dis[v] + revdis[u] + peso, dis[u] + revdis[v] + peso);
            long long offset = llabs(dis[t] - dist) + 1;
            if (offset >= peso || dis[t] >= INF)
            {
                cout << "NO\n";
            }
            else
            {
                cout << "CAN " << offset << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define MAX 100010
using namespace std;

typedef pair<long long,int> ii;

int n,m,s,t,a,b,l;

struct edge
{
    int x,y,peso;
    edge(int xx, int yy, int pesoo)
    {
        x = xx;
        y = yy;
        peso = pesoo;
    }

    bool operator < (edge a) const
    {
        if (x == a.x)
        {
            if (y == a.y)
            {
                return peso < a.peso;
            }
            return y < a.y;
        }
        return x < a.x;
    }
};

vector<int> adj[MAX], w[MAX], revadj[MAX], revw[MAX], spadj[MAX], spw[MAX];
set< edge > S;
long long dis[MAX];
long long revdis[MAX];
vector<edge> edges;
int dfsnum[MAX];
int dfslow[MAX];
int num;

void pontes(int p, int l)
{
    dfsnum[p] = dfslow[p] = num++;

    for (int i = 0; i < spadj[p].size(); ++i)
    {
        int v = spadj[p][i];
        int peso = spw[p][i];

        if (v == l) continue;
        if (dfsnum[v] == 0)
        {
            pontes(v, p);
            if (dfslow[v] > dfsnum[p])
            {
                edge tmp1(p, v, peso);
                S.insert(tmp1);
            }
            dfslow[p] = min(dfslow[p], dfslow[v]);
        }
        else
        {
            dfslow[p] = min(dfslow[p], dfsnum[v]);
        }
    }
}

void dijkstra(long long dis[MAX], vector<int> adj[MAX], vector<int> w[MAX], int s, int t)
{
    for (int i = 0; i < MAX; ++i)
    {
        dis[i] = 1000000000110LL;
    }

    priority_queue<ii, vector<ii>, greater<ii> > pq;

    dis[s] = 0;
    pq.push(make_pair(dis[s],s));

    while (!pq.empty())
    {
        long long peso = pq.top().first;
        int v = pq.top().second;
        pq.pop();

        if (peso != dis[v])
        {
            continue;
        }

        if (v == t)
        {
            return;
        }
        for (int i = 0; i < adj[v].size(); ++i)
        {
            int u = adj[v][i];
            long long pesot = w[v][i];
            if (dis[u] > dis[v] + pesot)
            {
                dis[u] = dis[v] + pesot;
                pq.push(make_pair(dis[u], u));
            }
        }
    }

}

int main(void)
{
    cin >> n >> m >> s >> t;

    for (int i = 0; i < m; ++i)
    {
        cin >> a >> b >> l;
        adj[a].push_back(b);
        w[a].push_back(l);
        revadj[b].push_back(a);
        revw[b].push_back(l);
        edge tmp(a,b,l);
        edges.push_back(tmp);
    }

    dijkstra(dis, adj, w, s, t);
    dijkstra(revdis, revadj, revw, t, s);

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;

        if (dis[v] + revdis[u] + (long long)peso == dis[t] || revdis[v] + dis[u] + (long long)peso == dis[t])
        {
            spadj[v].push_back(u);
            spw[v].push_back(peso);
        }
    }

    num = 1;

    for (int i = 1; i <= n; ++i)
    {
        if (dfsnum[i] == 0)
            pontes(i, i);
    }

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;
        if (S.count(edges[i]))
        {
            cout << "YES\n";
        }
        else
        {
            long long dist = min(dis[v] + revdis[u] + peso, dis[u] + revdis[v] + peso);
            long long offset = abs(dis[t] - dist) + 1;
            if (offset >= peso)
            {
                cout << "NO\n";
            }
            else
            {
                cout << "CAN " << offset << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define MAX 100010
using namespace std;

typedef pair<long long,int> ii;
const long long INF = 10000000000110LL;
int n,m,s,t,a,b,l;

struct edge
{
    int x,y,peso;
    edge(int xx, int yy, int pesoo)
    {
        x = xx;
        y = yy;
        peso = pesoo;
    }

    bool operator < (edge a) const
    {
        if (x == a.x)
        {
            if (y == a.y)
            {
                return peso < a.peso;
            }
            return y < a.y;
        }
        return x < a.x;
    }
};

vector<int> adj[MAX], w[MAX], revadj[MAX], revw[MAX], spadj[MAX], spw[MAX];
set< edge > S;
long long dis[MAX];
long long revdis[MAX];
vector<edge> edges;
int dfsnum[MAX];
int dfslow[MAX];
int num;
map<edge, int>  cnt;

void pontes(int p, int l)
{
    dfsnum[p] = dfslow[p] = num++;

    for (int i = 0; i < spadj[p].size(); ++i)
    {
        int v = spadj[p][i];
        int peso = spw[p][i];

        if (v == l) continue;
        if (dfsnum[v] == 0)
        {
            pontes(v, p);
            if (dfslow[v] > dfsnum[p])
            {
                edge tmp1(p, v, peso);
                edge tmp2(v, p, peso);
                S.insert(tmp1);
                S.insert(tmp2);
            }
            dfslow[p] = min(dfslow[p], dfslow[v]);
        }
        else
        {
            dfslow[p] = min(dfslow[p], dfsnum[v]);
        }
    }
}

void dijkstra(long long dis[MAX], vector<int> adj[MAX], vector<int> w[MAX], int s, int t)
{
    for (int i = 0; i < MAX; ++i)
    {
        dis[i] = INF;
    }

    priority_queue<ii, vector<ii>, greater<ii> > pq;

    dis[s] = 0;
    pq.push(make_pair(dis[s],s));

    while (!pq.empty())
    {
        long long peso = pq.top().first;
        int v = pq.top().second;
        pq.pop();

        if (peso != dis[v])
        {
            continue;
        }

        for (int i = 0; i < adj[v].size(); ++i)
        {
            int u = adj[v][i];
            long long pesot = w[v][i];
            if (dis[u] > dis[v] + pesot)
            {
                dis[u] = dis[v] + pesot;
                pq.push(make_pair(dis[u], u));
            }
        }
    }

}

int main(void)
{
    cin >> n >> m >> s >> t;

    for (int i = 0; i < m; ++i)
    {
        cin >> a >> b >> l;

        adj[a].push_back(b);
        w[a].push_back(l);
        revadj[b].push_back(a);
        revw[b].push_back(l);

        edge tmp(a,b,l);
        edges.push_back(tmp);
        cnt[tmp]++;

    }

    dijkstra(dis, adj, w, s, t);
    dijkstra(revdis, revadj, revw, t, s);

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;

        if (dis[v] == INF || dis[u] == INF)
            continue;
        if (revdis[v] == INF || revdis[u] == INF)
            continue;

        if (dis[v] + revdis[u] + (long long)peso == dis[t])
        {
            spadj[v].push_back(u);
            spw[v].push_back(peso);
            spadj[u].push_back(v);
            spw[u].push_back(peso);
        }
    }

    num = 1;

    for (int i = 1; i <= n; ++i)
    {
        if (dfsnum[i] == 0)
            pontes(i, i);
    }

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;

        if (S.count(edges[i]) && cnt[edges[i]] == 1)
        {
            cout << "YES\n";
        }
        else
        {
            long long dist = -1;
            if (dis[v] < INF && revdis[u] < INF)
                dist = dis[v] + revdis[u] + (long long)peso;

            long long offset = llabs(dis[t] - dist) + 1;
            if (dist == -1 || offset >= (long long)peso || dis[t] >= INF)
            {
                cout << "NO\n";
            }
            else
            {
                cout << "CAN " << offset << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define MAX 100010
using namespace std;

typedef pair<long long,int> ii;
const long long INF = 1000000000110LL;
int n,m,s,t,a,b,l;

struct edge
{
    int x,y,peso;
    edge(int xx, int yy, int pesoo)
    {
        x = xx;
        y = yy;
        peso = pesoo;
    }

    bool operator < (edge a) const
    {
        if (x == a.x)
        {
            if (y == a.y)
            {
                return peso < a.peso;
            }
            return y < a.y;
        }
        return x < a.x;
    }
};

vector<int> adj[MAX], w[MAX], revadj[MAX], revw[MAX], spadj[MAX], spw[MAX];
set< edge > S;
long long dis[MAX];
long long revdis[MAX];
vector<edge> edges;
int dfsnum[MAX];
int dfslow[MAX];
int num;
map<edge, int>  cnt;

void pontes(int p, int l)
{
    dfsnum[p] = dfslow[p] = num++;

    for (int i = 0; i < spadj[p].size(); ++i)
    {
        int v = spadj[p][i];
        int peso = spw[p][i];

        if (v == l) continue;
        if (dfsnum[v] == 0)
        {
            pontes(v, p);
            if (dfslow[v] > dfsnum[p])
            {
                edge tmp1(p, v, peso);
                edge tmp2(v, p, peso);
                S.insert(tmp1);
                S.insert(tmp2);
            }
            dfslow[p] = min(dfslow[p], dfslow[v]);
        }
        else
        {
            dfslow[p] = min(dfslow[p], dfsnum[v]);
        }
    }
}

void dijkstra(long long dis[MAX], vector<int> adj[MAX], vector<int> w[MAX], int s, int t)
{
    for (int i = 0; i < MAX; ++i)
    {
        dis[i] = INF;
    }

    priority_queue<ii, vector<ii>, greater<ii> > pq;

    dis[s] = 0;
    pq.push(make_pair(dis[s],s));

    while (!pq.empty())
    {
        long long peso = pq.top().first;
        int v = pq.top().second;
        pq.pop();

        if (peso != dis[v])
        {
            continue;
        }

        for (int i = 0; i < adj[v].size(); ++i)
        {
            int u = adj[v][i];
            long long pesot = w[v][i];
            if (dis[u] > dis[v] + pesot)
            {
                dis[u] = dis[v] + pesot;
                pq.push(make_pair(dis[u], u));
            }
        }
    }

}

int main(void)
{
    cin >> n >> m >> s >> t;

    for (int i = 0; i < m; ++i)
    {
        cin >> a >> b >> l;

        adj[a].push_back(b);
        w[a].push_back(l);
        revadj[b].push_back(a);
        revw[b].push_back(l);

        edge tmp(a,b,l);
        edges.push_back(tmp);
        cnt[tmp]++;

    }

    dijkstra(dis, adj, w, s, t);
    dijkstra(revdis, revadj, revw, t, s);

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;

        if (dis[v] == 0x3f3f3f3f || dis[u] == 0x3f3f3f3f)
            continue;
        if (revdis[v] == 0x3f3f3f3f || revdis[u] == 0x3f3f3f3f)
            continue;

        if (dis[v] + revdis[u] + (long long)peso == dis[t])
        {
            spadj[v].push_back(u);
            spw[v].push_back(peso);
            spadj[u].push_back(v);
            spw[u].push_back(peso);
        }
    }

    num = 1;

    for (int i = 1; i <= n; ++i)
    {
        if (dfsnum[i] == 0)
            pontes(i, i);
    }

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;
        if (S.count(edges[i]) && cnt[edges[i]] == 1)
        {
            cout << "YES\n";
        }
        else
        {
            long long dist = 0;
            edge tmp(v, u, peso);
            if (cnt[tmp] > 0)
                dist = dis[v] + revdis[u] + (long long)peso;

            edge tmp1(u, v, peso);
            if (cnt[tmp1] > 0)
              dist = min(dist, dis[u] + revdis[v] + (long long)peso);
            long long offset = llabs(dis[t] - dist) + 1;
            if (offset >= (long long)peso || dis[t] >= INF)
            {
                cout << "NO\n";
            }
            else
            {
                cout << "CAN " << offset << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define MAX 100010
using namespace std;

typedef pair<long long,int> ii;
const long long INF = 1000000000110LL;
int n,m,s,t,a,b,l;

struct edge
{
    int x,y,peso;
    edge(int xx, int yy, int pesoo)
    {
        x = xx;
        y = yy;
        peso = pesoo;
    }

    bool operator < (edge a) const
    {
        if (x == a.x)
        {
            if (y == a.y)
            {
                return peso < a.peso;
            }
            return y < a.y;
        }
        return x < a.x;
    }
};

vector<int> adj[MAX], w[MAX], revadj[MAX], revw[MAX], spadj[MAX], spw[MAX];
set< edge > S;
long long dis[MAX];
long long revdis[MAX];
vector<edge> edges;
int dfsnum[MAX];
int dfslow[MAX];
int num;
map<edge, int>  cnt;

void pontes(int p, int l)
{
    dfsnum[p] = dfslow[p] = num++;

    for (int i = 0; i < spadj[p].size(); ++i)
    {
        int v = spadj[p][i];
        int peso = spw[p][i];

        if (v == l) continue;
        if (dfsnum[v] == 0)
        {
            pontes(v, p);
            edge tmp1(p, v, peso);
            edge tmp2(v, p, peso);
            if (dfslow[v] > dfsnum[p] && cnt[tmp1] <= 1 && cnt[tmp2] <= 1)
            {
                S.insert(tmp1);
                S.insert(tmp2);
            }
            dfslow[p] = min(dfslow[p], dfslow[v]);
        }
        else
        {
            dfslow[p] = min(dfslow[p], dfsnum[v]);
        }
    }
}

void dijkstra(long long dis[MAX], vector<int> adj[MAX], vector<int> w[MAX], int s, int t)
{
    for (int i = 0; i < MAX; ++i)
    {
        dis[i] = INF;
    }

    priority_queue<ii, vector<ii>, greater<ii> > pq;

    dis[s] = 0;
    pq.push(make_pair(dis[s],s));

    while (!pq.empty())
    {
        long long peso = pq.top().first;
        int v = pq.top().second;
        pq.pop();

        if (peso != dis[v])
        {
            continue;
        }

        if (v == t)
        {
            return;
        }
        for (int i = 0; i < adj[v].size(); ++i)
        {
            int u = adj[v][i];
            long long pesot = w[v][i];
            if (dis[u] > dis[v] + pesot)
            {
                dis[u] = dis[v] + pesot;
                pq.push(make_pair(dis[u], u));
            }
        }
    }

}

int main(void)
{
    cin >> n >> m >> s >> t;

    for (int i = 0; i < m; ++i)
    {
        cin >> a >> b >> l;
        adj[a].push_back(b);
        w[a].push_back(l);
        revadj[b].push_back(a);
        revw[b].push_back(l);
        edge tmp(a,b,l);
        edges.push_back(tmp);
        cnt[tmp]++;
    }

    dijkstra(dis, adj, w, s, t);
    dijkstra(revdis, revadj, revw, t, s);

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;

        if (dis[v] + revdis[u] + (long long)peso == dis[t] || revdis[v] + dis[u] + (long long)peso == dis[t])
        {
            spadj[v].push_back(u);
            spw[v].push_back(peso);
            spadj[u].push_back(v);
            spw[u].push_back(peso);
        }
    }

    num = 1;

    for (int i = 1; i <= n; ++i)
    {
        if (dfsnum[i] == 0)
            pontes(i, i);
    }

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;
        if ((dis[v] + revdis[u] + (long long)peso == dis[t] || revdis[v] + dis[u] + (long long)peso == dis[t]) && S.count(edges[i]))
        {
            cout << "YES\n";
        }
        else
        {
            long long dist = min(dis[v] + revdis[u] + peso, dis[u] + revdis[v] + peso);
            long long offset = abs(dis[t] - dist) + 1;
            if (offset >= peso || dist == INF)
            {
                cout << "NO\n";
            }
            else
            {
                cout << "CAN " << offset << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define MAX 100010
using namespace std;

typedef pair<long long,int> ii;

int n,m,s,t,a,b,l;

struct edge
{
    int x,y,peso;
    edge(int xx, int yy, int pesoo)
    {
        x = xx;
        y = yy;
        peso = pesoo;
    }

    bool operator < (edge a) const
    {
        if (x == a.x)
        {
            if (y == a.y)
            {
                return peso < a.peso;
            }
            return y < a.y;
        }
        return x < a.x;
    }
};

vector<int> adj[MAX], w[MAX], revadj[MAX], revw[MAX], spadj[MAX], spw[MAX];
set< edge > S;
long long dis[MAX];
long long revdis[MAX];
vector<edge> edges;
int dfsnum[MAX];
int dfslow[MAX];
int num;

void pontes(int p, int l)
{
    dfsnum[p] = dfslow[p] = num++;

    for (int i = 0; i < spadj[p].size(); ++i)
    {
        int v = spadj[p][i];
        int peso = spw[p][i];

        if (v == l) continue;
        if (dfsnum[v] == 0)
        {
            pontes(v, p);
            if (dfslow[v] > dfsnum[p])
            {
                edge tmp1(p, v, peso);
                edge tmp2(v, p, peso);

                S.insert(tmp1);
                S.insert(tmp2);
            }
            dfslow[p] = min(dfslow[p], dfslow[v]);
        }
        else
        {
            dfslow[p] = min(dfslow[p], dfsnum[v]);
        }
    }
}

void dijkstra(long long dis[MAX], vector<int> adj[MAX], vector<int> w[MAX], int s, int t)
{
    for (int i = 0; i < MAX; ++i)
    {
        dis[i] = 1000000000110LL;
    }

    priority_queue<ii, vector<ii>, greater<ii> > pq;

    dis[s] = 0;
    pq.push(make_pair(dis[s],s));

    while (!pq.empty())
    {
        long long peso = pq.top().first;
        int v = pq.top().second;
        pq.pop();

        if (peso != dis[v])
        {
            continue;
        }

        if (v == t)
        {
            return;
        }
        for (int i = 0; i < adj[v].size(); ++i)
        {
            int u = adj[v][i];
            long long pesot = w[v][i];
            if (dis[u] > dis[v] + pesot)
            {
                dis[u] = dis[v] + pesot;
                pq.push(make_pair(dis[u], u));
            }
        }
    }

}

int main(void)
{
    cin >> n >> m >> s >> t;

    for (int i = 0; i < m; ++i)
    {
        cin >> a >> b >> l;
        adj[a].push_back(b);
        w[a].push_back(l);
        revadj[b].push_back(a);
        revw[b].push_back(l);
        edge tmp(a,b,l);
        edges.push_back(tmp);
    }

    dijkstra(dis, adj, w, s, t);
    dijkstra(revdis, revadj, revw, t, s);

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;

        if (dis[v] + revdis[u] + (long long)peso == dis[t] || revdis[v] + dis[u] + (long long)peso == dis[t])
        {
            spadj[v].push_back(u);
            spw[v].push_back(peso);
            spadj[u].push_back(v);
            spw[u].push_back(peso);
        }
    }

    num = 1;

    for (int i = 1; i <= n; ++i)
    {
        if (dfsnum[i] == 0)
            pontes(i, i);
    }

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;
        if ((dis[v] + revdis[u] + (long long)peso == dis[t] || revdis[v] + dis[u] + (long long)peso == dis[t]) && S.count(edges[i]))
        {
            cout << "YES\n";
        }
        else
        {
            long long dist = min(dis[v] + revdis[u] + peso, dis[u] + revdis[v] + peso);
            long long offset = abs(dis[t] - dist) + 1;
            if (offset >= peso)
            {
                cout << "NO\n";
            }
            else
            {
                cout << "CAN " << offset << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define MAX 100010
using namespace std;

typedef pair<long long,int> ii;
const long long INF = 10000000000110LL;
int n,m,s,t,a,b,l;

struct edge
{
    int x,y,peso;
    edge(int xx, int yy, int pesoo)
    {
        x = xx;
        y = yy;
        peso = pesoo;
    }

    bool operator < (edge a) const
    {
        if (x == a.x)
        {
            if (y == a.y)
            {
                return peso < a.peso;
            }
            return y < a.y;
        }
        return x < a.x;
    }
};

vector<int> adj[MAX], w[MAX], revadj[MAX], revw[MAX], spadj[MAX], spw[MAX];
set< edge > S;
long long dis[MAX];
long long revdis[MAX];
vector<edge> edges;
int dfsnum[MAX];
int dfslow[MAX];
int num;
map<edge, int>  cnt;

void pontes(int p, int l)
{
    dfsnum[p] = dfslow[p] = num++;

    for (int i = 0; i < spadj[p].size(); ++i)
    {
        int v = spadj[p][i];
        int peso = spw[p][i];

        if (v == l) continue;
        if (dfsnum[v] == 0)
        {
            pontes(v, p);
            if (dfslow[v] > dfsnum[p])
            {
                edge tmp1(p, v, peso);
                edge tmp2(v, p, peso);
                S.insert(tmp1);
                S.insert(tmp2);
            }
            dfslow[p] = min(dfslow[p], dfslow[v]);
        }
        else
        {
            dfslow[p] = min(dfslow[p], dfsnum[v]);
        }
    }
}

void dijkstra(long long dis[MAX], vector<int> adj[MAX], vector<int> w[MAX], int s, int t)
{
    for (int i = 0; i < MAX; ++i)
    {
        dis[i] = INF;
    }

    priority_queue<ii, vector<ii>, greater<ii> > pq;

    dis[s] = 0;
    pq.push(make_pair(dis[s],s));

    while (!pq.empty())
    {
        long long peso = pq.top().first;
        int v = pq.top().second;
        pq.pop();

        if (peso != dis[v])
        {
            continue;
        }

        for (int i = 0; i < adj[v].size(); ++i)
        {
            int u = adj[v][i];
            long long pesot = w[v][i];
            if (dis[u] > dis[v] + pesot)
            {
                dis[u] = dis[v] + pesot;
                pq.push(make_pair(dis[u], u));
            }
        }
    }

}

int main(void)
{
    cin >> n >> m >> s >> t;

    for (int i = 0; i < m; ++i)
    {
        cin >> a >> b >> l;

        adj[a].push_back(b);
        w[a].push_back(l);
        revadj[b].push_back(a);
        revw[b].push_back(l);

        edge tmp(a,b,l);
        edges.push_back(tmp);
        cnt[tmp]++;

    }

    dijkstra(dis, adj, w, s, t);
    dijkstra(revdis, revadj, revw, t, s);

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;

        if (dis[v] == INF || dis[u] == INF)
            continue;
        if (revdis[v] == INF || revdis[u] == INF)
            continue;

        if (dis[v] + revdis[u] + (long long)peso == dis[t])
        {
            spadj[v].push_back(u);
            spw[v].push_back(peso);
            spadj[u].push_back(v);
            spw[u].push_back(peso);
        }
    }

    num = 1;

    for (int i = 1; i <= n; ++i)
    {
        if (dfsnum[i] == 0)
            pontes(i, i);
    }

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;

        if (S.count(edges[i]) && cnt[edges[i]] == 1)
        {
            cout << "YES\n";
        }
        else
        {
            long long dist = 0;
            edge tmp(v, u, peso);
            if (dis[v] < INF && revdis[u] < INF)
                dist = dis[v] + revdis[u] + (long long)peso;

            long long offset = llabs(dis[t] - dist) + 1;
            if (offset >= (long long)peso || dis[t] >= INF)
            {
                cout << "NO\n";
            }
            else
            {
                cout << "CAN " << offset << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define MAX 100010
using namespace std;

typedef pair<long long,int> ii;
const long long INF = 1000000000110LL;
int n,m,s,t,a,b,l;

struct edge
{
    int x,y,peso;
    edge(int xx, int yy, int pesoo)
    {
        x = xx;
        y = yy;
        peso = pesoo;
    }

    bool operator < (edge a) const
    {
        if (x == a.x)
        {
            if (y == a.y)
            {
                return peso < a.peso;
            }
            return y < a.y;
        }
        return x < a.x;
    }
};

vector<int> adj[MAX], w[MAX], revadj[MAX], revw[MAX], spadj[MAX], spw[MAX];
set< edge > S;
long long dis[MAX];
long long revdis[MAX];
vector<edge> edges;
int dfsnum[MAX];
int dfslow[MAX];
int num;
map<edge, int>  cnt;
map< pair<int,int>, int> mapa;

void pontes(int p, int l)
{
    dfsnum[p] = dfslow[p] = num++;

    for (int i = 0; i < spadj[p].size(); ++i)
    {
        int v = spadj[p][i];
        int peso = spw[p][i];

        if (v == l) continue;
        if (dfsnum[v] == 0)
        {
            pontes(v, p);
            edge tmp1(p, v, peso);
            edge tmp2(v, p, peso);
            if (dfslow[v] > dfsnum[p])
            {
                if (cnt[tmp1] <= 1)
                    S.insert(tmp1);
                if (cnt[tmp2] <= 1)
                    S.insert(tmp2);
            }
            dfslow[p] = min(dfslow[p], dfslow[v]);
        }
        else
        {
            dfslow[p] = min(dfslow[p], dfsnum[v]);
        }
    }
}

void dijkstra(long long dis[MAX], vector<int> adj[MAX], vector<int> w[MAX], int s, int t)
{
    for (int i = 0; i < MAX; ++i)
    {
        dis[i] = INF;
    }

    priority_queue<ii, vector<ii>, greater<ii> > pq;

    dis[s] = 0;
    pq.push(make_pair(dis[s],s));

    while (!pq.empty())
    {
        long long peso = pq.top().first;
        int v = pq.top().second;
        pq.pop();

        if (peso != dis[v])
        {
            continue;
        }

        if (v == t)
        {
            return;
        }
        for (int i = 0; i < adj[v].size(); ++i)
        {
            int u = adj[v][i];
            long long pesot = w[v][i];
            if (dis[u] > dis[v] + pesot)
            {
                dis[u] = dis[v] + pesot;
                pq.push(make_pair(dis[u], u));
            }
        }
    }

}

int main(void)
{
    cin >> n >> m >> s >> t;

    for (int i = 0; i < m; ++i)
    {
        cin >> a >> b >> l;
        if (!mapa.count(make_pair(a,b)))
            mapa[make_pair(a,b)] = l;
        else
            mapa[make_pair(a,b)] = min(mapa[make_pair(a,b)], l);

        edge tmp(a,b,l);
        edges.push_back(tmp);
        cnt[tmp]++;

    }

    for (auto it = mapa.begin(); it != mapa.end(); ++it)
    {
        int a = it->first.first;
        int b = it->first.second;
        int l = it->second;

        adj[a].push_back(b);
        w[a].push_back(l);
        revadj[b].push_back(a);
        revw[b].push_back(l);
    }

    dijkstra(dis, adj, w, s, t);
    dijkstra(revdis, revadj, revw, t, s);

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;

        if (dis[v] + revdis[u] + (long long)peso == dis[t] || revdis[v] + dis[u] + (long long)peso == dis[t])
        {
            spadj[v].push_back(u);
            spw[v].push_back(peso);
            spadj[u].push_back(v);
            spw[u].push_back(peso);
        }
    }

    num = 1;

    for (int i = 1; i <= n; ++i)
    {
        if (dfsnum[i] == 0)
            pontes(i, i);
    }

    for (int i = 0; i < edges.size(); ++i)
    {
        int v = edges[i].x;
        int u = edges[i].y;
        int peso = edges[i].peso;
        if ((dis[v] + revdis[u] + (long long)peso == dis[t] || revdis[v] + dis[u] + (long long)peso == dis[t]) && S.count(edges[i]))
        {
            cout << "YES\n";
        }
        else
        {
            long long dist = 0;
            edge tmp(v, u, peso);
            if (cnt[tmp] > 0)
                dist = dis[v] + revdis[u] + (long long)peso;

            edge tmp1(u, v, peso);
            if (cnt[tmp1] > 0)
              dist = min(dist, dis[u] + revdis[v] + (long long)peso);
            long long offset = llabs(dis[t] - dist) + 1;
            if (offset >= (long long)peso || dis[t] >= INF)
            {
                cout << "NO\n";
            }
            else
            {
                cout << "CAN " << offset << "\n";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N= 100009;
const int oo=0xfffffff;
struct P{
    int d,u;
    bool operator <(const P rhs)const{
        return d>rhs.d;
    }
};
int n;

vector<pair<int,int> > V[N],G[N];

int dis[N],vis[N];
void dijk(int s){
    priority_queue<P> Q;
    for(int i=0;i<=n;i++){
        dis[i]=oo;
        vis[i]=0;
    }
    dis[s]=0;
    Q.push((P){0,s});
    while(!Q.empty()){
        P x=Q.top();
        Q.pop();
        int u=x.u;
        if(vis[u])continue;
        vis[u]=1;
        for(int i=0;i<V[u].size();i++){
            int v=V[u][i].first,w=V[u][i].second;
            if(dis[v]>dis[u]+w){
                dis[v]=dis[u]+w;
                Q.push((P){dis[v],v});
            }
        }
    }
}

int dfn[N],low[N],tim;
map<pair<int,int>,int> ok,chongbian;
void dfs(int u,int f){
    dfn[u]=low[u]=++tim;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i].first;
        if(!dfn[v]){
            dfs(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]){
                ok[make_pair(min(u,v),max(u,v))]=1;
            }
        }else if(v!=f&&dfn[v]<low[u])
                low[u]=dfn[v];
    }
}
pair<pair<int,int>,int>save[N];
int op[N];
int main()
{
    int m,s,t;
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i=0;i<m;i++){
        scanf("%d%d%d",&save[i].first.first,&save[i].first.second,&save[i].second);
        V[save[i].first.first].push_back(make_pair(save[i].first.second,save[i].second));
        V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    int dis1[N],dis2[N];
    dijk(s);
    for(int i=1;i<=n;i++)dis1[i]=dis[i];
    dijk(t);
    for(int i=1;i<=n;i++)dis2[i]=dis[i];
    int Min=dis1[t];
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second,w=save[i].second;
        if(dis1[u]+dis2[v]+w==Min){
            op[i]=1;
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }else if(dis1[v]+dis2[u]+w==Min){
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            op[i]=1;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }
    }
    dfs(s,-1);
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second,w=save[i].second;
        if(op[i]){
            if(ok[make_pair(min(u,v),max(u,v))]){
                if(chongbian[make_pair(min(u,v),max(u,v))]>=2)
                    printf("CAN 1\n");
                else
                    printf("YES\n");
            }else{
                if(w>1){
                    printf("CAN 1\n");
                }else{
                    printf("NO\n");
                }
            }
        }else{
            int MM=min(dis1[u]+dis2[v],dis1[v]+dis2[u]);
            int Ans=Min-MM-1;
            if(Ans>=1){
                printf("CAN %d\n",w-Ans);
            }else{
                printf("NO\n");
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

const int N= 100009;
const long long oo=1LL<<60;
struct P{
    long long d;int u;
    bool operator <(const P rhs)const{
        return d>rhs.d;
    }
};
int n;

vector<pair<int,long long> > V[N],G[N];

long long dis[N];
int vis[N];
void dijk(int s){
    priority_queue<P> Q;
    for(int i=0;i<=n;i++){
        dis[i]=oo;
        vis[i]=0;
    }
    dis[s]=0;
    Q.push((P){0,s});
    while(!Q.empty()){
        P x=Q.top();
        Q.pop();
        int u=x.u;
        if(vis[u])continue;
        vis[u]=1;
        for(int i=0;i<V[u].size();i++){
            int v=V[u][i].first;
            long long w=V[u][i].second;
            if(dis[v]>dis[u]+w){
                dis[v]=dis[u]+w;
                Q.push((P){dis[v],v});
            }
        }
    }
}

int dfn[N],low[N],tim;
int ok[N];
void dfs(int u,int f){
    dfn[u]=low[u]=++tim;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i].first;
        if(!dfn[v]){
            dfs(v,G[u][i].second);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]){
                ok[G[u][i].second]=1;
            }
        }else if(v!=f&&dfn[v]<dfn[u])
                low[u]=min(dfn[v],low[u]);
    }
}
pair<pair<int,int>,int>save[N];
int op[N];
int main()
{
    int m,s,t;
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i=0;i<m;i++){
        scanf("%d%d%I64d",&save[i].first.first,&save[i].first.second,&save[i].second);
        V[save[i].first.first].push_back(make_pair(save[i].first.second,save[i].second));
       // V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    long long dis1[N],dis2[N];
    dijk(s);
    for(int i=1;i<=n;i++)dis1[i]=dis[i],V[i].clear();
    for(int i=0;i<m;i++){
        V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    dijk(t);
    for(int i=1;i<=n;i++)dis2[i]=dis[i];
    long long Min=dis1[t];
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(dis1[u]+w==dis1[v]&&dis2[v]+w==dis2[u]){
            op[i]=1;
            G[u].push_back(make_pair(v,i));
            G[v].push_back(make_pair(u,i));
        }
    }
    dfs(s,-1);
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(op[i]&&ok[make_pair(min(u,v),max(u,v))]){
            printf("YES\n");
        }else if(w-(dis1[t]-dis1[u]-dis2[v]-1)<w){
            printf("CAN %I64d\n", w-(dis1[t]-dis1[u]-dis2[v]-1));
        }else printf("NO\n");
    }
}


#include <bits/stdc++.h>

using namespace std;

const int N= 100009;
const int oo=0xfffffff;
struct P{
    int d,u;
    bool operator <(const P rhs)const{
        return d>rhs.d;
    }
};
int n;

vector<pair<int,int> > V[N],G[N];

int dis[N],vis[N];
void dijk(int s){
    priority_queue<P> Q;
    for(int i=0;i<=n;i++){
        dis[i]=oo;
        vis[i]=0;
    }
    dis[s]=0;
    Q.push((P){0,s});
    while(!Q.empty()){
        P x=Q.top();
        Q.pop();
        int u=x.u;
        if(vis[u])continue;
        vis[u]=1;
        for(int i=0;i<V[u].size();i++){
            int v=V[u][i].first,w=V[u][i].second;
            if(dis[v]>dis[u]+w){
                dis[v]=dis[u]+w;
                Q.push((P){dis[v],v});
            }
        }
    }
}

int dfn[N],low[N],tim;
map<pair<int,int>,int> ok,chongbian;
void dfs(int u,int f){
    dfn[u]=low[u]=++tim;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i].first;
        if(!dfn[v]){
            dfs(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]){
                ok[make_pair(min(u,v),max(u,v))]=1;
            }
        }else if(v!=f&&dfn[v]<low[u])
                low[u]=dfn[v];
    }
}
pair<pair<int,int>,int>save[N];
int op[N];
int main()
{
    int m,s,t;
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i=0;i<m;i++){
        scanf("%d%d%d",&save[i].first.first,&save[i].first.second,&save[i].second);
        V[save[i].first.first].push_back(make_pair(save[i].first.second,save[i].second));
        V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    int dis1[N],dis2[N];
    dijk(s);
    for(int i=1;i<=n;i++)dis1[i]=dis[i];
    dijk(t);
    for(int i=1;i<=n;i++)dis2[i]=dis[i];
    int Min=dis1[t];
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second,w=save[i].second;
        if(dis1[u]+dis2[v]+w==Min){
            op[i]=1;
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }else if(dis1[v]+dis2[u]+w==Min){
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            op[i]=1;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }
    }
    dfs(s,-1);
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second,w=save[i].second;
        if(op[i]){
            if(ok[make_pair(min(u,v),max(u,v))]){
                if(chongbian[make_pair(min(u,v),max(u,v))])
                    printf("CAN 1\n");
                else
                    printf("YES\n");
            }else{
                if(w>1){
                    printf("CAN 1\n");
                }else{
                    printf("NO\n");
                }
            }
        }else{
            int MM=min(dis1[u]+dis2[v],dis1[v]+dis2[u]);
            int Ans=Min-MM-1;
            if(Ans>=1){
                printf("CAN %d\n",w-Ans);
            }else{
                printf("NO\n");
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

const int N= 100009;
const long long oo=1LL<<60;
struct P{
    long long d;int u;
    bool operator <(const P rhs)const{
        return d>rhs.d;
    }
};
int n;

vector<pair<int,long long> > V[N],G[N];

long long dis[N];
int vis[N];
void dijk(int s){
    priority_queue<P> Q;
    for(int i=0;i<=n;i++){
        dis[i]=oo;
        vis[i]=0;
    }
    dis[s]=0;
    Q.push((P){0,s});
    while(!Q.empty()){
        P x=Q.top();
        Q.pop();
        int u=x.u;
        if(vis[u])continue;
        vis[u]=1;
        for(int i=0;i<V[u].size();i++){
            int v=V[u][i].first;
            long long w=V[u][i].second;
            if(dis[v]>dis[u]+w){
                dis[v]=dis[u]+w;
                Q.push((P){dis[v],v});
            }
        }
    }
}

int dfn[N],low[N],tim;
int ok[N];
void dfs(int u,int f){
    dfn[u]=low[u]=++tim;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i].first;
        if(!dfn[v]){
            dfs(v,G[u][i].second);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]){
                ok[G[u][i].second]=1;
            }
        }else if(v!=f&&dfn[v]<dfn[u])
                low[u]=min(dfn[v],low[u]);
    }
}
pair<pair<int,int>,int>save[N];
int op[N];
int main()
{
    int m,s,t;
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i=0;i<m;i++){
        scanf("%d%d%I64d",&save[i].first.first,&save[i].first.second,&save[i].second);
        V[save[i].first.first].push_back(make_pair(save[i].first.second,save[i].second));
       // V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    long long dis1[N],dis2[N];
    dijk(s);
    for(int i=1;i<=n;i++)dis1[i]=dis[i],V[i].clear();
    for(int i=0;i<m;i++){
        V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    dijk(t);
    for(int i=1;i<=n;i++)dis2[i]=dis[i];
    long long Min=dis1[t];
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(dis1[u]+w==dis1[v]&&dis2[v]+w==dis2[u]){
            op[i]=1;
            G[u].push_back(make_pair(v,i));
            G[v].push_back(make_pair(u,i));
        }
    }
    dfs(s,-1);
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(ok[i]){
            printf("YES\n");
        }else if(w-(dis1[t]-dis1[u]-dis2[v]-1)<w){
            printf("CAN %I64d\n", w-(dis1[t]-dis1[u]-dis2[v]-1));
        }else printf("NO\n");
    }
}


#include <bits/stdc++.h>

using namespace std;

const int N= 100009;
const long long oo=1LL<<60;
struct P{
    long long d;int u;
    bool operator <(const P rhs)const{
        return d>rhs.d;
    }
};
int n;

vector<pair<int,long long> > V[N],G[N];

long long dis[N];
int vis[N];
void dijk(int s){
    priority_queue<P> Q;
    for(int i=0;i<=n;i++){
        dis[i]=oo;
        vis[i]=0;
    }
    dis[s]=0;
    Q.push((P){0,s});
    while(!Q.empty()){
        P x=Q.top();
        Q.pop();
        int u=x.u;
        if(vis[u])continue;
        vis[u]=1;
        for(int i=0;i<V[u].size();i++){
            int v=V[u][i].first;
            long long w=V[u][i].second;
            if(dis[v]>dis[u]+w){
                dis[v]=dis[u]+w;
                Q.push((P){dis[v],v});
            }
        }
    }
}

int dfn[N],low[N],tim;
map<pair<int,int>,int> ok,chongbian;
void dfs(int u,int f){
    dfn[u]=low[u]=++tim;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i].first;
        if(!dfn[v]){
            dfs(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]){
                ok[make_pair(min(u,v),max(u,v))]=1;
            }
        }else if(v!=f&&dfn[v]<low[u])
                low[u]=dfn[v];
    }
}
pair<pair<int,int>,int>save[N];
int op[N];
int main()
{
    int m,s,t;
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i=0;i<m;i++){
        scanf("%d%d%I64d",&save[i].first.first,&save[i].first.second,&save[i].second);
        V[save[i].first.first].push_back(make_pair(save[i].first.second,save[i].second));
       // V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    long long dis1[N],dis2[N];
    dijk(s);
    for(int i=1;i<=n;i++)dis1[i]=dis[i],V[i].clear();
    for(int i=0;i<m;i++){
        V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    dijk(t);
    for(int i=1;i<=n;i++)dis2[i]=dis[i];
    long long Min=dis1[t];
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(dis1[u]+dis2[v]+w==Min){
            op[i]=1;
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }else if(dis1[v]+dis2[u]+w==Min){
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            op[i]=1;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }
    }
    dfs(s,-1);
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(op[i]){
            if(ok[make_pair(min(u,v),max(u,v))]){
                if(chongbian[make_pair(min(u,v),max(u,v))]>=2)
                    {
                        if(t==80152)printf("*");
                        printf("CAN 1\n");
                    }
                else
                    printf("YES\n");
            }else{
                if(w>1){

                    printf("CAN 1\n");
                }else{
                    printf("NO\n");
                }
            }
        }else{
            if(w-(dis1[t]-dis1[u]-dis2[v]-1)<w){
                printf("CAN %I64d\n", w-(dis1[t]-dis1[u]-dis2[v]-1));
            }else{
                puts("NO");
            }

        }
    }
}


#include <bits/stdc++.h>

using namespace std;

const int N= 100009;
const long long oo=1LL<<60;
struct P{
    long long d;int u;
    bool operator <(const P rhs)const{
        return d>rhs.d;
    }
};
int n;

vector<pair<int,long long> > V[N],G[N];

long long dis[N];
int vis[N];
void dijk(int s){
    priority_queue<P> Q;
    for(int i=0;i<=n;i++){
        dis[i]=oo;
        vis[i]=0;
    }
    dis[s]=0;
    Q.push((P){0,s});
    while(!Q.empty()){
        P x=Q.top();
        Q.pop();
        int u=x.u;
        if(vis[u])continue;
        vis[u]=1;
        for(int i=0;i<V[u].size();i++){
            int v=V[u][i].first;
            long long w=V[u][i].second;
            if(dis[v]>dis[u]+w){
                dis[v]=dis[u]+w;
                Q.push((P){dis[v],v});
            }
        }
    }
}

int dfn[N],low[N],tim;
map<pair<int,int>,int> ok,chongbian;
void dfs(int u,int f){
    dfn[u]=low[u]=++tim;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i].first;
        if(!dfn[v]){
            dfs(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]){
                ok[make_pair(min(u,v),max(u,v))]=1;
            }
        }else if(v!=f&&dfn[v]<low[u])
                low[u]=dfn[v];
    }
}
pair<pair<int,int>,int>save[N];
int op[N];
int main()
{
    int m,s,t;
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i=0;i<m;i++){
        scanf("%d%d%I64d",&save[i].first.first,&save[i].first.second,&save[i].second);
        V[save[i].first.first].push_back(make_pair(save[i].first.second,save[i].second));
       // V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    long long dis1[N],dis2[N];
    dijk(s);
    for(int i=1;i<=n;i++)dis1[i]=dis[i],V[i].clear();
    for(int i=0;i<m;i++){
        V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    dijk(t);
    for(int i=1;i<=n;i++)dis2[i]=dis[i];
    long long Min=dis1[t];
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(dis1[u]+dis2[v]+w==Min){
            op[i]=1;
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }else if(dis1[v]+dis2[u]+w==Min){
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            op[i]=1;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }
    }
    dfs(s,-1);
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(op[i]){
            if(ok[make_pair(min(u,v),max(u,v))]){
                if(chongbian[make_pair(min(u,v),max(u,v))]>=2)
                    printf("CAN 1\n");
                else
                    printf("YES\n");
            }else{
                if(w>1){
                    printf("CAN 1\n");
                }else{
                    printf("NO\n");
                }
            }
        }else{
            if(w-(dis1[t]-dis1[u]-dis2[v]-1)<w){
                printf("CAN %I64d\n", w-(dis1[t]-dis1[u]-dis2[v]-1));
            }else{
                puts("NO");
            }

        }
    }
}


#include <bits/stdc++.h>

using namespace std;

const int N= 100009;
const long long oo=1LL<<60;
struct P{
    long long d;int u;
    bool operator <(const P rhs)const{
        return d>rhs.d;
    }
};
int n;

vector<pair<int,long long> > V[N],G[N];

long long dis[N];
int vis[N];
void dijk(int s){
    priority_queue<P> Q;
    for(int i=0;i<=n;i++){
        dis[i]=oo;
        vis[i]=0;
    }
    dis[s]=0;
    Q.push((P){0,s});
    while(!Q.empty()){
        P x=Q.top();
        Q.pop();
        int u=x.u;
        if(vis[u])continue;
        vis[u]=1;
        for(int i=0;i<V[u].size();i++){
            int v=V[u][i].first;
            long long w=V[u][i].second;
            if(dis[v]>dis[u]+w){
                dis[v]=dis[u]+w;
                Q.push((P){dis[v],v});
            }
        }
    }
}

int dfn[N],low[N],tim;
map<pair<int,int>,int> ok,chongbian;
void dfs(int u,int f){
    dfn[u]=low[u]=++tim;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i].first;
        if(!dfn[v]){
            dfs(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]){
                ok[make_pair(min(u,v),max(u,v))]=1;
            }
        }else if(v!=f&&dfn[v]<low[u])
                low[u]=dfn[v];
    }
}
pair<pair<int,int>,int>save[N];
int op[N];
int main()
{
    int m,s,t;
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i=0;i<m;i++){
        scanf("%d%d%I64d",&save[i].first.first,&save[i].first.second,&save[i].second);
        V[save[i].first.first].push_back(make_pair(save[i].first.second,save[i].second));
       // V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    long long dis1[N],dis2[N];
    dijk(s);
    for(int i=1;i<=n;i++)dis1[i]=dis[i],V[i].clear();
    for(int i=0;i<m;i++){
        V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    dijk(t);
    for(int i=1;i<=n;i++)dis2[i]=dis[i];
    long long Min=dis1[t];
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(dis1[u]+dis2[v]+w==Min){
            op[i]=1;
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }else if(dis1[v]+dis2[u]+w==Min){
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            op[i]=1;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }
    }
    dfs(s,-1);
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(op[i]){
            if(ok[make_pair(min(u,v),max(u,v))]){
                if(chongbian[make_pair(min(u,v),max(u,v))]>=2)
                    {
                        //if(t==80152)printf("*");
                        printf("CAN 1\n");
                    }
                else
                    printf("YES\n");
            }else{
                if(w>1){

                    printf("CAN 1\n");
                }else{
                    printf("NO\n");
                }
            }
        }else{
            if(w-(dis1[t]-dis1[u]-dis2[v]-1)<w){
                if(t==80152)printf("*");
                printf("CAN %I64d\n", w-(dis1[t]-dis1[u]-dis2[v]-1));
            }else{
                puts("NO");
            }

        }
    }
}


#include <bits/stdc++.h>

using namespace std;

const int N= 100009;
const long long oo=1LL<<60;
struct P{
    long long d;int u;
    bool operator <(const P rhs)const{
        return d>rhs.d;
    }
};
int n;

vector<pair<int,long long> > V[N],G[N];

long long dis[N];
int vis[N];
void dijk(int s){
    priority_queue<P> Q;
    for(int i=0;i<=n;i++){
        dis[i]=oo;
        vis[i]=0;
    }
    dis[s]=0;
    Q.push((P){0,s});
    while(!Q.empty()){
        P x=Q.top();
        Q.pop();
        int u=x.u;
        if(vis[u])continue;
        vis[u]=1;
        for(int i=0;i<V[u].size();i++){
            int v=V[u][i].first;
            long long w=V[u][i].second;
            if(dis[v]>dis[u]+w){
                dis[v]=dis[u]+w;
                Q.push((P){dis[v],v});
            }
        }
    }
}

int dfn[N],low[N],tim;
map<pair<int,int>,int> ok,chongbian;
void dfs(int u,int f){
    dfn[u]=low[u]=++tim;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i].first;
        if(!dfn[v]){
            dfs(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]){
                ok[make_pair(min(u,v),max(u,v))]=1;
            }
        }else if(v!=f&&dfn[v]<low[u])
                low[u]=dfn[v];
    }
}
pair<pair<int,int>,int>save[N];
int op[N];
int main()
{
    int m,s,t;
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i=0;i<m;i++){
        scanf("%d%d%I64d",&save[i].first.first,&save[i].first.second,&save[i].second);
        V[save[i].first.first].push_back(make_pair(save[i].first.second,save[i].second));
       // V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    long long dis1[N],dis2[N];
    dijk(s);
    for(int i=1;i<=n;i++)dis1[i]=dis[i],V[i].clear();
    for(int i=0;i<m;i++){
        V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    dijk(t);
    for(int i=1;i<=n;i++)dis2[i]=dis[i];
    long long Min=dis1[t];
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(dis1[u]+dis2[v]+w==Min){
            op[i]=1;
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }else if(dis1[v]+dis2[u]+w==Min){
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            op[i]=1;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }
    }
    dfs(s,-1);
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(op[i]){
            if(ok[make_pair(min(u,v),max(u,v))]){
                if(chongbian[make_pair(min(u,v),max(u,v))]>=2)
                    {
                        if(t==80152&&s==65669)printf("*1");
                        printf("CAN 1\n");
                    }
                else
                    printf("YES\n");
            }else{
                if(w>1){
                    if(t==80152&&s==65669)printf("*2");
                    printf("CAN 1\n");
                }else{
                    printf("NO\n");
                }
            }
        }else{
            if(w-(dis1[t]-dis1[u]-dis2[v]-1)<w){
                if(t==80152&&s==65669)printf("*3");
                printf("CAN %I64d\n", w-(dis1[t]-dis1[u]-dis2[v]-1));
            }else{
                puts("NO");
            }

        }
    }
}


#include <bits/stdc++.h>

using namespace std;

const int N= 100009;
const long long oo=1LL<<60;
struct P{
    long long d;int u;
    bool operator <(const P rhs)const{
        return d>rhs.d;
    }
};
int n;

vector<pair<int,long long> > V[N],G[N];

long long dis[N];
int vis[N];
void dijk(int s){
    priority_queue<P> Q;
    for(int i=0;i<=n;i++){
        dis[i]=oo;
        vis[i]=0;
    }
    dis[s]=0;
    Q.push((P){0,s});
    while(!Q.empty()){
        P x=Q.top();
        Q.pop();
        int u=x.u;
        if(vis[u])continue;
        vis[u]=1;
        for(int i=0;i<V[u].size();i++){
            int v=V[u][i].first;
            long long w=V[u][i].second;
            if(dis[v]>dis[u]+w){
                dis[v]=dis[u]+w;
                Q.push((P){dis[v],v});
            }
        }
    }
}

int dfn[N],low[N],tim;
int ok[N];
void dfs(int u,int f){
    dfn[u]=low[u]=++tim;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i].first;
        if(!dfn[v]){
            dfs(v,G[u][i].second);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]){
                ok[G[u][i].second]=1;
            }
        }else if(G[u][i].second!=f&&dfn[v]<dfn[u])
                low[u]=min(dfn[v],low[u]);
    }
}
pair<pair<int,int>,int>save[N];
int op[N];
int main()
{
    int m,s,t;
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i=0;i<m;i++){
        scanf("%d%d%I64d",&save[i].first.first,&save[i].first.second,&save[i].second);
        V[save[i].first.first].push_back(make_pair(save[i].first.second,save[i].second));
       // V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    long long dis1[N],dis2[N];
    dijk(s);
    for(int i=1;i<=n;i++)dis1[i]=dis[i],V[i].clear();
    for(int i=0;i<m;i++){
        V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    dijk(t);
    for(int i=1;i<=n;i++)dis2[i]=dis[i];
    long long Min=dis1[t];
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(dis1[u]+w==dis1[v]&&dis2[v]+w==dis2[u]){
            G[u].push_back(make_pair(v,i));
            G[v].push_back(make_pair(u,i));
        }
    }
    dfs(s,-1);
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(ok[i]){
            printf("YES\n");
        }else if(w-(dis1[t]-dis1[u]-dis2[v]-1)<w){
            printf("CAN %I64d\n", w-(dis1[t]-dis1[u]-dis2[v]-1));
        }else printf("NO\n");
    }
}


#include <bits/stdc++.h>

using namespace std;

const int N= 100009;
const long long oo=1LL<<60;
struct P{
    long long d;int u;
    bool operator <(const P rhs)const{
        return d>rhs.d;
    }
};
int n;

vector<pair<int,long long> > V[N],G[N];

long long dis[N];
int vis[N];
void dijk(int s){
    priority_queue<P> Q;
    for(int i=0;i<=n;i++){
        dis[i]=oo;
        vis[i]=0;
    }
    dis[s]=0;
    Q.push((P){0,s});
    while(!Q.empty()){
        P x=Q.top();
        Q.pop();
        int u=x.u;
        if(vis[u])continue;
        vis[u]=1;
        for(int i=0;i<V[u].size();i++){
            int v=V[u][i].first;
            long long w=V[u][i].second;
            if(dis[v]>dis[u]+w){
                dis[v]=dis[u]+w;
                Q.push((P){dis[v],v});
            }
        }
    }
}

int dfn[N],low[N],tim;
map<pair<int,int>,int> ok,chongbian;
void dfs(int u,int f){
    dfn[u]=low[u]=++tim;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i].first;
        if(!dfn[v]){
            dfs(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]){
                ok[make_pair(min(u,v),max(u,v))]=1;
            }
        }else if(v!=f&&dfn[v]<low[u])
                low[u]=dfn[v];
    }
}
pair<pair<int,int>,int>save[N];
int op[N];
int main()
{
    int m,s,t;
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i=0;i<m;i++){
        scanf("%d%d%I64d",&save[i].first.first,&save[i].first.second,&save[i].second);
        V[save[i].first.first].push_back(make_pair(save[i].first.second,save[i].second));
       // V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    long long dis1[N],dis2[N];
    dijk(s);
    for(int i=1;i<=n;i++)dis1[i]=dis[i],V[i].clear();
    for(int i=0;i<m;i++){
        V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    dijk(t);
    for(int i=1;i<=n;i++)dis2[i]=dis[i];
    long long Min=dis1[t];
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(dis1[u]+dis2[v]+w==Min){
            op[i]=1;
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }else if(dis1[v]+dis2[u]+w==Min){
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            op[i]=1;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }
    }
    dfs(s,-1);
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(op[i]){
            if(ok[make_pair(min(u,v),max(u,v))]){
                if(chongbian[make_pair(min(u,v),max(u,v))]>=2)
                    printf("CAN 1\n");
                else
                    printf("YES\n");
            }else{
                if(w>1){
                    if(t==80152)printf("*");
                    printf("CAN 1\n");
                }else{
                    printf("NO\n");
                }
            }
        }else{
            if(w-(dis1[t]-dis1[u]-dis2[v]-1)<w){
                printf("CAN %I64d\n", w-(dis1[t]-dis1[u]-dis2[v]-1));
            }else{
                puts("NO");
            }

        }
    }
}


#include <bits/stdc++.h>

using namespace std;

const int N= 100009;
const long long oo=1LL<<60;
struct P{
    long long d;int u;
    bool operator <(const P rhs)const{
        return d>rhs.d;
    }
};
int n;

vector<pair<int,long long> > V[N],G[N];

long long dis[N];
int vis[N];
void dijk(int s){
    priority_queue<P> Q;
    for(int i=0;i<=n;i++){
        dis[i]=oo;
        vis[i]=0;
    }
    dis[s]=0;
    Q.push((P){0,s});
    while(!Q.empty()){
        P x=Q.top();
        Q.pop();
        int u=x.u;
        if(vis[u])continue;
        vis[u]=1;
        for(int i=0;i<V[u].size();i++){
            int v=V[u][i].first;
            long long w=V[u][i].second;
            if(dis[v]>dis[u]+w){
                dis[v]=dis[u]+w;
                Q.push((P){dis[v],v});
            }
        }
    }
}

int dfn[N],low[N],tim;
map<pair<int,int>,int> ok,chongbian;
void dfs(int u,int f){
    dfn[u]=low[u]=++tim;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i].first;
        if(!dfn[v]){
            dfs(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]){
                ok[make_pair(min(u,v),max(u,v))]=1;
            }
        }else if(v!=f&&dfn[v]<low[u])
                low[u]=dfn[v];
    }
}
pair<pair<int,int>,int>save[N];
int op[N];
int main()
{
    int m,s,t;
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i=0;i<m;i++){
        scanf("%d%d%I64d",&save[i].first.first,&save[i].first.second,&save[i].second);
        V[save[i].first.first].push_back(make_pair(save[i].first.second,save[i].second));
       // V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    long long dis1[N],dis2[N];
    dijk(s);
    for(int i=1;i<=n;i++)dis1[i]=dis[i],V[i].clear();
    for(int i=0;i<m;i++){
        V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    dijk(t);
    for(int i=1;i<=n;i++)dis2[i]=dis[i];
    long long Min=dis1[t];
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(dis1[u]+dis2[v]+w==Min){
            op[i]=1;
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }else if(dis1[v]+dis2[u]+w==Min){
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            op[i]=1;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }
    }
    dfs(s,-1);
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(op[i]){
            if(ok[make_pair(min(u,v),max(u,v))]){
                if(chongbian[make_pair(min(u,v),max(u,v))]>=2)
                    {
                        if(t==18384&&s==65669)printf("CAO1");
                        printf("CAN 1\n");
                    }
                else
                    printf("YES\n");
            }else{
                if(w>1){
                    if(t==18384&&s==65669)printf("CAO2");
                    printf("CAN 1\n");
                }else{
                    printf("NO\n");
                }
            }
        }else{
            if(w-(dis1[t]-dis1[u]-dis2[v]-1)<w){
                if(t==18384&&s==65669)printf("CAO3");
                printf("CAN %I64d\n", w-(dis1[t]-dis1[u]-dis2[v]-1));
            }else{
                puts("NO");
            }

        }
    }
}


#include <bits/stdc++.h>

using namespace std;

const int N= 100009;
const long long oo=1LL<<60;
struct P{
    long long d;int u;
    bool operator <(const P rhs)const{
        return d>rhs.d;
    }
};
int n;

vector<pair<int,long long> > V[N],G[N];

long long dis[N];
int vis[N];
void dijk(int s){
    priority_queue<P> Q;
    for(int i=0;i<=n;i++){
        dis[i]=oo;
        vis[i]=0;
    }
    dis[s]=0;
    Q.push((P){0,s});
    while(!Q.empty()){
        P x=Q.top();
        Q.pop();
        int u=x.u;
        if(vis[u])continue;
        vis[u]=1;
        for(int i=0;i<V[u].size();i++){
            int v=V[u][i].first;
            long long w=V[u][i].second;
            if(dis[v]>dis[u]+w){
                dis[v]=dis[u]+w;
                Q.push((P){dis[v],v});
            }
        }
    }
}

int dfn[N],low[N],tim;
map<pair<int,int>,int> ok,chongbian;
void dfs(int u,int f){
    dfn[u]=low[u]=++tim;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i].first;
        if(!dfn[v]){
            dfs(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]){
                ok[make_pair(min(u,v),max(u,v))]=1;
            }
        }else if(v!=f&&dfn[v]<low[u])
                low[u]=dfn[v];
    }
}
pair<pair<int,int>,int>save[N];
int op[N];
int main()
{
    int m,s,t;
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i=0;i<m;i++){
        scanf("%d%d%I64d",&save[i].first.first,&save[i].first.second,&save[i].second);
        V[save[i].first.first].push_back(make_pair(save[i].first.second,save[i].second));
       // V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    long long dis1[N],dis2[N];
    dijk(s);
    for(int i=1;i<=n;i++)dis1[i]=dis[i],V[i].clear();
    for(int i=0;i<m;i++){
        V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    dijk(t);
    for(int i=1;i<=n;i++)dis2[i]=dis[i];
    long long Min=dis1[t];
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(dis1[u]+w==dis1[v]&&dis2[v]+w==dis2[u]){
            op[i]=1;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }
    }
    dfs(s,-1);
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second;long long w=save[i].second;
        if(op[i]&&ok[make_pair(min(u,v),max(u,v))]){
            printf("YES\n");
        }else if(w-(dis1[t]-dis1[u]-dis2[v]-1)<w){
            printf("CAN %I64d\n", w-(dis1[t]-dis1[u]-dis2[v]-1));
        }else printf("NO\n");
    }
}


#include <bits/stdc++.h>

using namespace std;

const int N= 100009;
const int oo=0xfffffff;
struct P{
    int d,u;
    bool operator <(const P rhs)const{
        return d>rhs.d;
    }
};
int n;

vector<pair<int,int> > V[N],G[N];

int dis[N],vis[N];
void dijk(int s){
    priority_queue<P> Q;
    for(int i=0;i<=n;i++){
        dis[i]=oo;
        vis[i]=0;
    }
    dis[s]=0;
    Q.push((P){0,s});
    while(!Q.empty()){
        P x=Q.top();
        Q.pop();
        int u=x.u;
        if(vis[u])continue;
        vis[u]=1;
        for(int i=0;i<V[u].size();i++){
            int v=V[u][i].first,w=V[u][i].second;
            if(dis[v]>dis[u]+w){
                dis[v]=dis[u]+w;
                Q.push((P){dis[v],v});
            }
        }
    }
}

int dfn[N],low[N],tim;
map<pair<int,int>,int> ok,chongbian;
void dfs(int u,int f){
    dfn[u]=low[u]=++tim;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i].first;
        if(!dfn[v]){
            dfs(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]){
                ok[make_pair(min(u,v),max(u,v))]=1;
            }
        }else if(v!=f&&dfn[v]<low[u])
                low[u]=dfn[v];
    }
}
pair<pair<int,int>,int>save[N];
int op[N];
int main()
{
    int m,s,t;
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i=0;i<m;i++){
        scanf("%d%d%d",&save[i].first.first,&save[i].first.second,&save[i].second);
        V[save[i].first.first].push_back(make_pair(save[i].first.second,save[i].second));
       // V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    int dis1[N],dis2[N];
    dijk(s);
    for(int i=1;i<=n;i++)dis1[i]=dis[i],V[i].clear();
    for(int i=0;i<m;i++){
        V[save[i].first.second].push_back(make_pair(save[i].first.first,save[i].second));
    }
    dijk(t);
    for(int i=1;i<=n;i++)dis2[i]=dis[i];
    int Min=dis1[t];
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second,w=save[i].second;
        if(dis1[u]+dis2[v]+w==Min){
            op[i]=1;
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }else if(dis1[v]+dis2[u]+w==Min){
            chongbian[make_pair(min(u,v),max(u,v))]++;
            if(chongbian[make_pair(min(u,v),max(u,v))]>=2)continue;
            op[i]=1;
            G[u].push_back(make_pair(v,w));
            G[v].push_back(make_pair(u,w));
        }
    }
    dfs(s,-1);
    for(int i=0;i<m;i++){
        int u=save[i].first.first,v=save[i].first.second,w=save[i].second;
        if(op[i]){
            if(ok[make_pair(min(u,v),max(u,v))]){
                if(chongbian[make_pair(min(u,v),max(u,v))]>=2)
                    printf("CAN 1\n");
                else
                    printf("YES\n");
            }else{
                if(w>1){
                    printf("CAN 1\n");
                }else{
                    printf("NO\n");
                }
            }
        }else{
            if(w-(dis1[t]-dis1[u]-dis2[v]-1)<w){
                printf("CAN %d\n", w-(dis1[t]-dis1[u]-dis2[v]-1));
            }else{
                puts("NO");
            }

        }
    }
}