#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[200005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

int rettt = 0;bool fff = 0;

void dfs1(int x, int ord)
{
	if(fff == 1){
		printf("%d\n",x);
		rettt++;
		if(rettt > 1000000)return;
	}
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
		}
		rett++;
		if(fff == 1)if(rett > 1000000)break;
		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 8360)fff = 1;
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}

	dfs1(s, 1);
	if(fff != 1){
	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();

	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[3000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

bool fff = 0;

void work_sum()
{
	int x = s;
//	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
//		if(i == 1)if(a == 88226)fff = 1;
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}
	dfs1(s, 1);
	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();
//	if(fff != 1){
	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
//	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

long long diss[100005], dist[100005];
int q[200005], open, last;
bool vis[100005], pvis[100005];

int rettt = 0;bool fff = 0;int ffff = 0;

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		if(fff == 1){
			if(x == s) ffff++;
			//if(rettt > 1000000 && ffff > 1)printf("%d\n",x);
			if(rettt > 1000000)printf("%d %d\n",open,last);
			rettt++;
			if(rettt > 2000000)return;
		}
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
//	if(fff == 1){
//		printf("%d\n",x);
//		rettt++;
//		if(rettt > 1000000)return;
//	}
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 50000)fff = 1;
	}

	spfas();
	if(fff != 1){
	spfat();

	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + (long long)ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}

	dfs1(s, 1);

	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();

	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

long long diss[100005], dist[100005];
//int q[200005], open, last;
bool vis[100005];// pvis[100005];

int rettt = 0;bool fff = 0;int ffff = 0;

/*
void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		if(fff == 1){
			if(x == s) ffff++;
			//if(rettt > 1000000 && ffff > 1)printf("%d\n",x);
			if(rettt > 1000000)printf("%d %d\n",open,last);
			rettt++;
			if(rettt > 2000000)return;
		}
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}
*/
/*
void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}
*/
int sizeh;
int pos[100005];

struct mod
{
	int ver;
	long long dis;
}heap[100005];

void up(int x)
{
	while(x > 1){
		long long tmp = heap[x >> 1].dis;
		if((heap[x].dis < tmp && heap[x].dis != -1) || (heap[x].dis != -1 && tmp == -1)){
			mod k;
			k = heap[x]; heap[x] = heap[x >> 1]; heap[x >> 1] = k;
			pos[heap[x].ver] = x;
			pos[heap[x >> 1].ver] = x >> 1;
			x = x >> 1;
		}else break;
	}
}

void down()
{
	int x = 1;
	while(((x << 1) + 1) <= sizeh){
		long long tmp = 0;
		int fl = -1;
		if((heap[x << 1].dis <= heap[(x << 1) + 1].dis && heap[x << 1].dis != -1) ||
			(heap[x << 1].dis == -1 && heap[(x << 1) + 1].dis == -1) ||
			(heap[x << 1].dis != -1 && heap[(x << 1) + 1].dis == -1))tmp = heap[x << 1].dis, fl = 0;
		else tmp = heap[(x << 1) + 1].dis, fl = 1;
		if((heap[x].dis > tmp && tmp != -1) || (heap[x].dis == -1 && tmp != -1)){
			mod k;
			k = heap[x]; heap[x] = heap[(x << 1) + fl]; heap[(x << 1) + fl] = k;
			pos[heap[x].ver] = x;
			pos[heap[(x << 1) + fl].ver] = (x << 1) + fl;
			x = (x << 1) + fl;
		}else break;
	}
}

void build_heaps()
{
	sizeh = 0;
	for(int i = 1; i <= n; i++){
		sizeh++;
		heap[sizeh].ver = i;
		heap[sizeh].dis = diss[i];
		pos[i] = sizeh;
		up(sizeh);
	}
}

void build_heapt()
{
	sizeh = 0;
	for(int i = 1; i <= n; i++){
		sizeh++;
		heap[sizeh].ver = i;
		heap[sizeh].dis = dist[i];
		pos[i] = sizeh;
		up(sizeh);
	}
}

//int maxn = 0;

void dijs()
{
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	diss[s] = 0;
	build_heaps();
	for(int i = 1; i <= n; i++){
		int x = heap[1].ver;
		vis[x] = 1;
		heap[1] = heap[sizeh];
		sizeh--;
		down();
		for(int j = heads[x]; j; j = ps[j].next){
			int v = ps[j].v, c = ps[j].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				heap[pos[v]].dis = diss[v];
				up(pos[v]);
//				if(maxn < sizeh)maxn = sizeh;
			}
		}
	}
}

void dijt()
{
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	dist[t] = 0;
	build_heapt();
	for(int i = 1; i <= n; i++){
		int x = heap[1].ver;
		vis[x] = 1;
		heap[1] = heap[sizeh];
		sizeh--;
		down();
		for(int j = headt[x]; j; j = pt[j].next){
			int v = pt[j].v, c = pt[j].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				heap[pos[v]].dis = dist[v];
				up(pos[v]);
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
//	if(fff == 1){
//		printf("%d\n",x);
//		rettt++;
//		if(rettt > 1000000)return;
//	}
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 29663)fff = 1;
	}

	//spfas();

	//spfat();
	dijs();
	dijt();
//	if(fff == 1)printf("%d\n",maxn);
//	if(fff != 1){
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + (long long)ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}

	dfs1(s, 1);

	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();

	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
//	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].sum = 0;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].sum = 0;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[1000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

int sumt = 0;

void dfs(int x)
{
	if(x == t){
		sumt++;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			if(vis[v] == 0){
				ps[i].sum++;
				vis[v] = 1;
				dfs(v);
				vis[v] = 0;
			}
		}
	}
}

void dfs1(int x)
{
	if(x == t)return;
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next)if(ps[i].fshort == 1)tmp++;
	if(tmp == 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1){
				int v = ps[i].v;
				ps[i].fyes = 1;
				dfs1(v);
			}
		}
	}
}

int main()
{
	freopen("test.in", "r", stdin);
	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 0;
		}
	}
	for(int i = 1; i <= n; i++)vis[i] = 0;
	dfs(s);
	for(int i = 1; i <= m; i++)if(ps[i].sum == sumt)ps[i].fyes = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0;
	dfs1(s);
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 0){
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
			else printf("YES\n");
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[1000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	do{
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}while(x != t);
}

bool fff = 0;

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 88226)fff = 1;
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}
	dfs1(s, 1);
	for(int i = 1; i <= n; i++)vis[i] = 0;

		work_sum();
	if(fff != 1){int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[2000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

bool fff = 0;

void work_sum()
{
	int x = s;
//	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
//		if(i == 1)if(a == 88226)fff = 1;
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}
	dfs1(s, 1);
	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();
//	if(fff != 1){
	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
//	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].sum = 0;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].sum = 0;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[1000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

int sumt = 0;

void dfs(int x)
{
	if(x == t){
		sumt++;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			if(vis[v] == 0){
				ps[i].sum++;
				vis[v] = 1;
				dfs(v);
				vis[v] = 0;
			}
		}
	}
}

void dfs1(int x)
{
	if(x == t)return;
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next)if(ps[i].fshort == 1)tmp++;
	if(tmp == 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1){
				int v = ps[i].v;
				ps[i].fyes = 1;
				dfs1(v);
			}
		}
	}
}

int main()
{
	//freopen("test.in", "r", stdin);
	//freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 0;
		}
	}
	for(int i = 1; i <= n; i++)vis[i] = 0;
	dfs(s);
	for(int i = 1; i <= m; i++)if(ps[i].sum == sumt)ps[i].fyes = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0;
	dfs1(s);
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans > ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 0)printf("CAN 1\n");
			else printf("YES\n");
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
bool sums[100005], sume[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[1000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

void dfs(int x)
{
	if(vis[x] == 1)return;
	vis[x] = 1;
	if(x == t)return;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			if(fmain[x] == 1 && fmain[v] == 0)sums[x] = 1;
			if(fmain[x] == 0 && fmain[v] == 1)sume[v] = 1;
			if(fmain[x] == 1 && fmain[v] == 1 && ps[i].fmain == 0)sums[x] = 1, sume[v] = 1;
			dfs(v);
		}
	}
	/*if(x == t){
		sumt++;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			if(vis[v] == 0){
				ps[i].sum++;
				vis[v] = 1;
				dfs(v);
				vis[v] = 0;
			}
		}
	}*/
}

bool flag = 0;

void dfs1(int x)
{
	fmain[x] = 1;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v);
		if(flag == 1)return;
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}
	for(int i = 1; i <= n; i++)vis[i] = 0;
	dfs1(s);
	dfs(s);
	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[1000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	do{
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}while(x != t);
}

bool fff = 0;

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 88226)fff = 1;
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}
	dfs1(s, 1);
	for(int i = 1; i <= n; i++)vis[i] = 0;
	if(fff != 1){
		work_sum();
	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

long long diss[100005], dist[100005];
//int q[200005], open, last;
bool vis[100005];// pvis[100005];

int rettt = 0;bool fff = 0;int ffff = 0;

/*
void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		if(fff == 1){
			if(x == s) ffff++;
			//if(rettt > 1000000 && ffff > 1)printf("%d\n",x);
			if(rettt > 1000000)printf("%d %d\n",open,last);
			rettt++;
			if(rettt > 2000000)return;
		}
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}
*/
/*
void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}
*/
int sizeh;

struct mod
{
	int ver;
	long long dis;
}heap[1000005];

void up()
{
	int x = sizeh;
	while(x > 1){
		long long tmp = heap[x >> 1].dis;
		if(heap[x].dis < tmp || (heap[x].dis != -1 && tmp == -1)){
			mod k;
			k = heap[x]; heap[x] = heap[x >> 1]; heap[x >> 1] = k;
			x = x >> 1;
		}else break;
	}
}

void down()
{
	int x = 1;
	while(((x << 1) + 1) <= sizeh){
		long long tmp = 0;
		int fl = -1;
		if((heap[x << 1].dis <= heap[(x << 1) + 1].dis && heap[x << 1].dis != -1) ||
			(heap[x << 1].dis == -1 && heap[(x << 1) + 1].dis == -1) ||
			(heap[x << 1].dis != -1 && heap[(x << 1) + 1].dis == -1))tmp = heap[x << 1].dis, fl = 0;
		else tmp = heap[(x << 1) + 1].dis, fl = 1;
		if(heap[x].dis > tmp || (heap[x].dis == -1 && tmp != -1)){
			mod k;
			k = heap[x]; heap[x] = heap[(x << 1) + fl]; heap[(x << 1) + fl] = k;
			x = (x << 1) + fl;
		}else break;
	}
}

void build_heaps()
{
	sizeh = n;
	for(int i = 1; i <= n; i++)heap[i].ver = i, heap[i].dis = diss[i];
	for(int i = n; i >= 1; i--)up();
}

void build_heapt()
{
	sizeh = n;
	for(int i = 1; i <= n; i++)heap[i].ver = i, heap[i].dis = dist[i];
	for(int i = n; i >= 1; i--)up();
}

void dijs()
{
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	diss[s] = 0;
	build_heaps();
	for(int i = 1; i <= n; i++){
		int x = heap[1].ver;
		vis[x] = 1;
		while(vis[heap[sizeh].ver] == 1)sizeh--;
		heap[1] = heap[sizeh];
		sizeh--;
		down();
		for(int j = heads[x]; j; j = ps[j].next){
			int v = ps[j].v, c = ps[j].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				sizeh++;
				heap[sizeh].ver = v;
				heap[sizeh].dis = diss[v];
				up();
			}
		}
	}
}

void dijt()
{
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	dist[t] = 0;
	build_heapt();
	for(int i = 1; i <= n; i++){
		int x = heap[1].ver;
		vis[x] = 1;
		while(vis[heap[sizeh].ver] == 1)sizeh--;
		heap[1] = heap[sizeh];
		sizeh--;
		down();
		for(int j = headt[x]; j; j = pt[j].next){
			int v = pt[j].v, c = pt[j].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				sizeh++;
				heap[sizeh].ver = v;
				heap[sizeh].dis = dist[v];
				up();
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
//	if(fff == 1){
//		printf("%d\n",x);
//		rettt++;
//		if(rettt > 1000000)return;
//	}
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 50000)fff = 1;
	}

	//spfas();
//	if(fff != 1){
	//spfat();
	dijs();
	dijt();

	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + (long long)ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}

	dfs1(s, 1);

	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();

	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
//	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[1000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

bool fff = 0;

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
		}
		rett++;
		if(fff == 1)if(rett > 1000000)break;
		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 88226)fff = 1;
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}
	dfs1(s, 1);
	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();
	if(fff != 1){int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

long long diss[100005], dist[100005];
//int q[200005], open, last;
bool vis[100005];// pvis[100005];

int rettt = 0;bool fff = 0;int ffff = 0;

/*
void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		if(fff == 1){
			if(x == s) ffff++;
			//if(rettt > 1000000 && ffff > 1)printf("%d\n",x);
			if(rettt > 1000000)printf("%d %d\n",open,last);
			rettt++;
			if(rettt > 2000000)return;
		}
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}
*/
/*
void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}
*/
int sizeh;

struct mod
{
	int ver;
	long long dis;
}heap[10000005];

void up()
{
	int x = sizeh;
	while(x > 1){
		long long tmp = heap[x >> 1].dis;
		if((heap[x].dis < tmp && heap[x].dis != -1) || (heap[x].dis != -1 && tmp == -1)){
			mod k;
			k = heap[x]; heap[x] = heap[x >> 1]; heap[x >> 1] = k;
			x = x >> 1;
		}else break;
	}
}

void down()
{
	int x = 1;
	while(((x << 1) + 1) <= sizeh){
		long long tmp = 0;
		int fl = -1;
		if((heap[x << 1].dis <= heap[(x << 1) + 1].dis && heap[x << 1].dis != -1) ||
			(heap[x << 1].dis == -1 && heap[(x << 1) + 1].dis == -1) ||
			(heap[x << 1].dis != -1 && heap[(x << 1) + 1].dis == -1))tmp = heap[x << 1].dis, fl = 0;
		else tmp = heap[(x << 1) + 1].dis, fl = 1;
		if((heap[x].dis > tmp && tmp != -1) || (heap[x].dis == -1 && tmp != -1)){
			mod k;
			k = heap[x]; heap[x] = heap[(x << 1) + fl]; heap[(x << 1) + fl] = k;
			x = (x << 1) + fl;
		}else break;
	}
}

void build_heaps()
{
	sizeh = n;
	for(int i = 1; i <= n; i++)heap[i].ver = i, heap[i].dis = diss[i];
	for(int i = n; i >= 1; i--)up();
}

void build_heapt()
{
	sizeh = n;
	for(int i = 1; i <= n; i++)heap[i].ver = i, heap[i].dis = dist[i];
	for(int i = n; i >= 1; i--)up();
}

int maxn = 0;

void dijs()
{
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	diss[s] = 0;
	build_heaps();
	for(int i = 1; i <= n; i++){
		int x = heap[1].ver;
		vis[x] = 1;
		while(vis[heap[sizeh].ver] == 1)sizeh--;
		heap[1] = heap[sizeh];
		sizeh--;
		down();
		for(int j = heads[x]; j; j = ps[j].next){
			int v = ps[j].v, c = ps[j].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				sizeh++;
				heap[sizeh].ver = v;
				heap[sizeh].dis = diss[v];
				up();
				if(maxn < sizeh)maxn = sizeh;
			}
		}
	}
}

void dijt()
{
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	dist[t] = 0;
	build_heapt();
	for(int i = 1; i <= n; i++){
		int x = heap[1].ver;
		vis[x] = 1;
		while(vis[heap[sizeh].ver] == 1)sizeh--;
		heap[1] = heap[sizeh];
		sizeh--;
		down();
		for(int j = headt[x]; j; j = pt[j].next){
			int v = pt[j].v, c = pt[j].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				sizeh++;
				heap[sizeh].ver = v;
				heap[sizeh].dis = dist[v];
				up();
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
//	if(fff == 1){
//		printf("%d\n",x);
//		rettt++;
//		if(rettt > 1000000)return;
//	}
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 29663)fff = 1;
	}

	//spfas();

	//spfat();
	dijs();
	dijt();
	if(fff == 1)printf("%d\n",maxn);
	if(fff != 1){
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + (long long)ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}

	dfs1(s, 1);

	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();

	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[2000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 2000000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 2000000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

bool fff = 0;

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
		}
		rett++;
		if(fff == 1)if(rett > 1000000)break;
		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 8360)fff = 1;
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}
	if(fff != 1){
	dfs1(s, 1);
	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();

	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

long long diss[100005], dist[100005];
int q[200005], open, last;
bool vis[100005], pvis[100005];

int rettt = 0;bool fff = 0;

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		if(fff == 1){
			if(rettt > 1000000)printf("%d\n",x);
			rettt++;
			if(rettt > 2000000)return;
		}
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
//	if(fff == 1){
//		printf("%d\n",x);
//		rettt++;
//		if(rettt > 1000000)return;
//	}
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 50000)fff = 1;
	}

	spfas();
	if(fff != 1){
	spfat();

	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + (long long)ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}

	dfs1(s, 1);

	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();

	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

int diss[100005], dist[100005];
int q[1000005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + c){
				diss[v] = diss[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open < last){
		open++;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + c){
				dist[v] = dist[x] + c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

void dfs1(int x, int ord)
{
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

bool fff = 0;

void work_sum()
{
	int x = s;
	do{
		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
		}
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}while(x != t);
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 88226)fff = 1;
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}
	dfs1(s, 1);
	for(int i = 1; i <= n; i++)vis[i] = 0;

		work_sum();
	if(fff != 1){int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include <cstdio>
#include <algorithm>

using namespace std;

int n, m, s, t;
struct mode
{
	int v, c, next, sum;
	bool fshort, fyes, fmain;
}ps[100005], pt[100005];
int heads[100005], sizes, headt[100005], sizet;
int sums[100005], sume[100005], order[100005];
bool fmain[100005];

void add(int u, int v, int c)
{
	sizes++;
	ps[sizes].v = v;
	ps[sizes].c = c;
	ps[sizes].next = heads[u];
	ps[sizes].fshort = ps[sizes].fyes = 0;
	heads[u] = sizes;

	sizet++;
	pt[sizet].v = u;
	pt[sizet].c = c;
	pt[sizet].next = headt[v];
	pt[sizet].fshort = pt[sizet].fyes = 0;
	headt[v] = sizet;
}

long long diss[100005], dist[100005];
int q[200005], open, last;
bool vis[100005], pvis[100005];

void spfas()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, diss[i] = -1;
	q[1] = s; vis[s] = 1; diss[s] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = heads[x]; i; i = ps[i].next){
			int v = ps[i].v, c = ps[i].c;
			if(diss[v] == -1 || diss[v] > diss[x] + (long long)c){
				diss[v] = diss[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

void spfat()
{
	open = 0; last = 1;
	for(int i = 1; i <= n; i++)vis[i] = 0, dist[i] = -1;
	q[1] = t; vis[t] = 1; dist[t] = 0;
	while(open != last){
		open++;
		if(open > 200000)open = 1;
		int x = q[open];
		vis[x] = 0;
		for(int i = headt[x]; i; i = pt[i].next){
			int v = pt[i].v, c = pt[i].c;
			if(dist[v] == -1 || dist[v] > dist[x] + (long long)c){
				dist[v] = dist[x] + (long long)c;
				if(vis[v] == 0){
					vis[v] = 1;
					last++;
					if(last > 200000)last = 1;
					q[last] = v;
				}
			}
		}
	}
}

bool flag = 0;

int rettt = 0;bool fff = 0;

void dfs1(int x, int ord)
{
//	if(fff == 1){
//		printf("%d\n",x);
//		rettt++;
//		if(rettt > 1000000)return;
//	}
	fmain[x] = 1;
	order[x] = ord;
	if(x == t){
		flag = 1;
		return;
	}
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1)ps[i].fmain = 1, dfs1(ps[i].v, ord + 1);
		if(flag == 1)return;
	}
}

int vlast[100005];

int dfs(int x)
{
	if(vis[x] == 1)return vlast[x];
	vis[x] = 1;
	if(fmain[x] == 1){
		vlast[x] = x;
		return x;
	}
	int tmp = 0;
	for(int i = heads[x]; i; i = ps[i].next){
		if(ps[i].fshort == 1){
			int v = ps[i].v;
			int ret = dfs(v);
			if(order[ret] > order[tmp])tmp = ret;
		}
	}
	vlast[x] = tmp;
	return tmp;
}

void work_sum()
{
	int x = s;
	int rett = 0;
	while(x != t){
//		if(fff != 1){
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fshort == 1 && ps[i].fmain == 0){
				int ret = 0;
				ret = dfs(ps[i].v);
				sums[x]++;
				sume[ret]++;
			}
		}
//		}
//		rett++;
//		if(fff == 1)if(rett > 1000000)break;
//		if(fff == 1)printf("%d\n",x);
		for(int i = heads[x]; i; i = ps[i].next)
			if(ps[i].fmain == 1){
				x = ps[i].v;
				break;
			}
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i = 1; i<= m; i++){
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		add(a, b, l);
		if(i == 1)if(a == 50000)fff = 1;
	}
	spfas();
	spfat();
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] != -1 && dist[v] != -1 && diss[u] + dist[v] + (long long)ps[i].c == diss[t]){
			ps[i].fshort = pt[i].fshort = 1;
			ps[i].fyes = pt[i].fyes = 1;
		}
	}

	dfs1(s, 1);
	if(fff != 1){
	for(int i = 1; i <= n; i++)vis[i] = 0;

	work_sum();

	int x = s, tmp = 0;
	while(x != t){
		tmp -= sume[x];
		tmp += sums[x];
		for(int i = heads[x]; i; i = ps[i].next){
			if(ps[i].fmain == 1){
				if(tmp > 0)ps[i].fyes = 0;
				x = ps[i].v;
				break;
			}
		}
	}
	}
	for(int i = 1; i <= m; i++){
		int u = pt[i].v;
		int v = ps[i].v;
		if(diss[u] == -1 || dist[v] == -1)printf("NO\n");
		if(ps[i].fshort == 0){
			if(diss[u] != -1 && dist[v] != -1){
				int ans = diss[u] + dist[v] + ps[i].c - diss[t] + 1;
				if(ans < ps[i].c)printf("CAN %d\n", ans);
				else printf("NO\n");
			}
		}else{
			if(ps[i].fyes == 1 && ps[i].fmain == 1)printf("YES\n");
			else{
				if(ps[i].c > 1)printf("CAN 1\n");
				else printf("NO\n");
			}
		}
	}
	return 0;
	}


#include<bits/stdc++.h>
#define MAXN 100010
#define MAXC 27
using namespace std;
typedef long long LL;
typedef pair<LL,int> P;
struct edge{
    int to,next,cost,dir;
}E[MAXN*2];
LL ldist[MAXN],rdist[MAXN];
int head[MAXN],si,N,M,s,t,used[MAXN],dfn[MAXN],low[MAXN],idx;
LL ans[MAXN];
priority_queue< P, vector<P>, greater<P> > que;
void add_edge(int u,int v,int w,int d)
{
    E[si].to=v;
    E[si].cost=w;
    E[si].next=head[u];
    E[si].dir=d;
    head[u]=si++;
}
void init()
{
    memset(ldist,0x3f,sizeof ldist);
    memset(rdist,0x3f,sizeof rdist);
    ldist[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(p.first>ldist[v])continue;
        for(int i=head[v];~i;i=E[i].next){
            int u=E[i].to;
            if(!E[i].dir)continue;
            if(ldist[u]>ldist[v]+E[i].cost){
                ldist[u]=ldist[v]+E[i].cost;
                que.push(P(ldist[u],u));
            }
        }
    }
    memset(used,0,sizeof used);
    rdist[t]=0;
    que.push(P(0,t));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(p.first>rdist[v])continue;
        for(int i=head[v];~i;i=E[i].next){
            if(E[i].dir)continue;
            int u=E[i].to;
            if(rdist[u]>rdist[v]+E[i].cost){
                rdist[u]=rdist[v]+E[i].cost;
                que.push(P(rdist[u],u));
            }
        }
    }
}
void dfs(int v)
{
    if(v==t)return;
    for(int i=head[v];~i;i=E[i].next){
        int u=E[i].to;
        if(!used[i/2]){
            if(ldist[v]+E[i].cost+rdist[u]==ldist[t]){
                used[i/2]=true;
                dfs(u);
            }
        }

    }
}
void tarjan(int v,int pre)
{
    low[v]=++idx;
    dfn[v]=idx;
    for(int i=head[v];~i;i=E[i].next){
        int u=E[i].to;
        if(!used[i/2]||(i^1)==pre)continue;
        if(!dfn[u]){
            tarjan(u,i);
            low[v]=min(low[v],low[u]);
        }
        else{
            low[v]=min(low[v],dfn[u]);
        }
    }
    if(low[v]==dfn[v]){
        if(~pre)ans[pre/2]=0;
    }
}
int main() {
    while(cin>>N>>M>>s>>t){
        memset(head,-1,sizeof head);si=idx=0;
        for(int i=0,u,v,w;i<M;i++){
            scanf("%d%d%d",&u,&v,&w);
            add_edge(u,v,w,1);
            add_edge(v,u,w,0);
        }
     //   printf("si:%d\n",si);
        init();
       // printf("mindist:%I64d\n",ldist[t]);
        memset(used,0,sizeof used);
        dfs(s);
        memset(ans,-1,sizeof ans);
        tarjan(s,-1);
        for(int i=0;i<si;i++){
            if(~ans[i/2]||!E[i].dir)continue;
            int v=E[i].to,u=E[i^1].to;
            LL len=ldist[u]+rdist[v];
            if(len+1>=ldist[t])continue;
            ans[i/2]=len+E[i].cost-ldist[t]+1;
        }
        for(int i=0;i<si;i+=2){
            if(ans[i/2]==0){
                puts("YES");
            }
            else if(~ans[i/2]){
                printf("CAN %I64d\n",ans[i/2]);
            }
            else puts("NO");
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#define MAXN 100010
#define MAXC 27
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
struct edge{
    int to,next,cost, rev;
}E[MAXN*2];
LL ldist[MAXN],rdist[MAXN];
int head[MAXN],si,N,M,s,t,que[MAXN*2],used[MAXN],dfn[MAXN],low[MAXN],idx;
LL ans[MAXN];
void add_edge(int u,int v,int w, int r)
{
    E[si].to=v;
    E[si].cost=w;
    E[si].next=head[u];
    E[si].rev = r;
    head[u]=si++;
}
void init()
{
    memset(used,0,sizeof used);
    memset(ldist,0x3f,sizeof ldist);
    memset(rdist,0x3f,sizeof rdist);
    ldist[s]=0;
    int h=0,tail=0;
    que[tail++]=s;used[s]=true;
    while(h<tail){
        int v=que[h++];
        used[v]=false;
        for(int i=head[v];~i;i=E[i].next){
            if(E[i].rev == 1)
                continue;
            int u=E[i].to;
            if(ldist[u]>ldist[v]+E[i].cost){
                ldist[u]=ldist[v]+E[i].cost;
                if(!used[u]){
                    que[tail++]=u;
                    used[u]=true;
                }
            }
        }
    }
    memset(used,0,sizeof used);
    rdist[t]=0;
    h=0,tail=0;
    que[tail++]=t;used[t]=true;
    while(h<tail){
        int v=que[h++];
        used[v]=false;
        for(int i=head[v];~i;i=E[i].next){
            if(E[i].rev == 0)
                continue;
            int u=E[i].to;
            if(rdist[u]>rdist[v]+E[i].cost){
                rdist[u]=rdist[v]+E[i].cost;
                if(!used[u]){
                    que[tail++]=u;
                    used[u]=true;
                }
            }
        }
    }
}
void dfs(int v)
{
   // used[v]=true;
   // printf("used[%d]=true\n",v);
    if(v==t)return;
    for(int i=head[v];~i;i=E[i].next){
        int u=E[i].to;
          if(E[i].rev == 1)
                continue;
        if(!used[i/2]){
            if(ldist[v]+E[i].cost+rdist[u]==ldist[t]){
                used[i/2]=true;
                dfs(u);
            }
        }

    }
}
void tarjan(int v,int pre)
{
    low[v]=++idx;
    dfn[v]=idx;
    for(int i=head[v];~i;i=E[i].next){
        int u=E[i].to;
        if(!used[i/2]||(i^1)==pre)continue;
        if(!dfn[u]){
            tarjan(u,i);
            low[v]=min(low[v],low[u]);
        }
        else{
            low[v]=min(low[v],dfn[u]);
        }
        //if(~pre&&low[v]==dfn[v])ans[pre/2]=0;
    }
    //printf("%d:%d___%d\n",v,low[v],dfn[v]);
    if(low[v]==dfn[v]){
       // if(~pre)printf("%d->%d:%d_%d\n",E[pre].to,E[pre^1].to,pre,pre^1);
        if(~pre)ans[pre/2]=0;
    }
}
int main() {
    while(cin>>N>>M>>s>>t){
        memset(head,-1,sizeof head);si=idx=0;
        for(int i=0,u,v,w;i<M;i++){
            scanf("%d%d%d",&u,&v,&w);
            add_edge(u,v,w,0);
            add_edge(v,u,w,1);
        }
     //   printf("si:%d\n",si);
        init();
       // printf("mindist:%I64d\n",ldist[t]);
        memset(used,0,sizeof used);
        dfs(s);
        memset(ans,-1,sizeof ans);
        tarjan(s,-1);
        for(int i=0;i<si;i++){
            if(~ans[i/2])continue;
            int v=E[i].to,u=E[i^1].to;
            LL len=ldist[u]+rdist[v];
         //   printf("%d->%d:%I64d\n",u,v,len);
            if(len+1>=ldist[t])continue;
            ans[i/2]=len+E[i].cost-ldist[t]+1;
        }
        for(int i=0;i<si;i+=2){
            if(ans[i/2]==0){
                puts("YES");
            }
            else if(~ans[i/2]){
                printf("CAN %I64d\n",ans[i/2]);
            }
            else puts("NO");
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#define MAXN 100010
#define MAXC 27
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
struct edge{
    int to,next,cost, rev;
}E[MAXN*2];
LL ldist[MAXN],rdist[MAXN];
int head[MAXN],si,N,M,s,t,que[MAXN*2],used[MAXN],dfn[MAXN],low[MAXN],idx;
LL ans[MAXN];
void add_edge(int u,int v,int w, int r)
{
    E[si].to=v;
    E[si].cost=w;
    E[si].next=head[u];
    E[si].rev = r;
    head[u]=si++;
}
void init()
{
    memset(used,0,sizeof used);
    memset(ldist,0x3f,sizeof ldist);
    memset(rdist,0x3f,sizeof rdist);
    ldist[s]=0;
    int h=0,tail=0;
    que[tail++]=s;used[s]=true;
    while(h<tail){
        int v=que[h++];
        used[v]=false;
        for(int i=head[v];~i;i=E[i].next){
            if(E[i].rev == 1)
                continue;
            int u=E[i].to;
            if(ldist[u]>ldist[v]+E[i].cost){
                ldist[u]=ldist[v]+E[i].cost;
                if(!used[u]){
                    que[tail++]=u;
                    used[u]=true;
                }
            }
        }
    }
    memset(used,0,sizeof used);
    rdist[t]=0;
    h=0,tail=0;
    que[tail++]=t;used[t]=true;
    while(h<tail){
        int v=que[h++];
        used[v]=false;
        for(int i=head[v];~i;i=E[i].next){
            if(E[i].rev == 0)
                continue;
            int u=E[i].to;
            if(rdist[u]>rdist[v]+E[i].cost){
                rdist[u]=rdist[v]+E[i].cost;
                if(!used[u]){
                    que[tail++]=u;
                    used[u]=true;
                }
            }
        }
    }
}
void dfs(int v)
{
   // used[v]=true;
   // printf("used[%d]=true\n",v);
    if(v==t)return;
    for(int i=head[v];~i;i=E[i].next){
        int u=E[i].to;
        if(!used[i/2]){
            if(ldist[v]+E[i].cost+rdist[u]==ldist[t]){
                used[i/2]=true;
                dfs(u);
            }
        }

    }
}
void tarjan(int v,int pre)
{
    low[v]=++idx;
    dfn[v]=idx;
    for(int i=head[v];~i;i=E[i].next){
        int u=E[i].to;
        if(!used[i/2]||(i^1)==pre)continue;
        if(!dfn[u]){
            tarjan(u,i);
            low[v]=min(low[v],low[u]);
        }
        else{
            low[v]=min(low[v],dfn[u]);
        }
        //if(~pre&&low[v]==dfn[v])ans[pre/2]=0;
    }
    //printf("%d:%d___%d\n",v,low[v],dfn[v]);
    if(low[v]==dfn[v]){
       // if(~pre)printf("%d->%d:%d_%d\n",E[pre].to,E[pre^1].to,pre,pre^1);
        if(~pre)ans[pre/2]=0;
    }
}
int main() {
    while(cin>>N>>M>>s>>t){
        memset(head,-1,sizeof head);si=idx=0;
        for(int i=0,u,v,w;i<M;i++){
            scanf("%d%d%d",&u,&v,&w);
            add_edge(u,v,w,0);
            add_edge(v,u,w,1);
        }
     //   printf("si:%d\n",si);
        init();
       // printf("mindist:%I64d\n",ldist[t]);
        memset(used,0,sizeof used);
        dfs(s);
        memset(ans,-1,sizeof ans);
        tarjan(s,-1);
        for(int i=0;i<si;i++){
            if(~ans[i/2])continue;
            int v=E[i].to,u=E[i^1].to;
            LL len=min(ldist[v]+rdist[u],ldist[u]+rdist[v]);
         //   printf("%d->%d:%I64d\n",u,v,len);
            if(len+1>=ldist[t])continue;
            ans[i/2]=len+E[i].cost-ldist[t]+1;
        }
        for(int i=0;i<si;i+=2){
            if(ans[i/2]==0){
                puts("YES");
            }
            else if(~ans[i/2]){
                printf("CAN %I64d\n",ans[i/2]);
            }
            else puts("NO");
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define MAXN 100010
#define MAXC 27
using namespace std;
typedef long long LL;
typedef pair<LL,int> P;
struct edge{
    int to,next,cost,dir;
}E[MAXN*2];
LL ldist[MAXN],rdist[MAXN];
int head[MAXN],si,N,M,s,t,used[MAXN],dfn[MAXN],low[MAXN],idx;
LL ans[MAXN];
priority_queue< P, vector<P>, greater<P> > que;
void add_edge(int u,int v,int w,int d)
{
    E[si].to=v;
    E[si].cost=w;
    E[si].next=head[u];
    E[si].dir=d;
    head[u]=si++;
}
void init()
{
    memset(ldist,0x3f,sizeof ldist);
    memset(rdist,0x3f,sizeof rdist);
    ldist[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(p.first>ldist[v])continue;
        for(int i=head[v];~i;i=E[i].next){
            int u=E[i].to;
            if(!E[i].dir)continue;
            if(ldist[u]>ldist[v]+E[i].cost){
                ldist[u]=ldist[v]+E[i].cost;
                que.push(P(ldist[u],u));
            }
        }
    }
    memset(used,0,sizeof used);
    rdist[t]=0;
    que.push(P(0,t));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(p.first>rdist[v])continue;
        for(int i=head[v];~i;i=E[i].next){
            if(E[i].dir)continue;
            int u=E[i].to;
            if(rdist[u]>rdist[v]+E[i].cost){
                rdist[u]=rdist[v]+E[i].cost;
                que.push(P(rdist[u],u));
            }
        }
    }
}
void dfs(int v)
{
    if(v==t)return;
    for(int i=head[v];~i;i=E[i].next){
        int u=E[i].to;
        if(!used[i/2]){
            if(ldist[v]+E[i].cost+rdist[u]==ldist[t]){
                used[i/2]=true;
                dfs(u);
            }
        }

    }
}
void tarjan(int v,int pre)
{
    low[v]=++idx;
    dfn[v]=idx;
    for(int i=head[v];~i;i=E[i].next){
        int u=E[i].to;
        if(!used[i/2]||(i^1)==pre)continue;
        if(!dfn[u]){
            tarjan(u,i);
            low[v]=min(low[v],low[u]);
        }
        else{
            low[v]=min(low[v],dfn[u]);
        }
    }
    if(low[v]==dfn[v]){
        if(~pre)ans[pre/2]=0;
    }
}
int main() {
    scanf("%d%d%d%d",&N,&M,&s,&t);
    memset(head,-1,sizeof head);si=idx=0;
    for(int i=0,u,v,w;i<M;i++){
        scanf("%d%d%d",&u,&v,&w);
        add_edge(u,v,w,1);
        add_edge(v,u,w,0);
    }
 //   printf("si:%d\n",si);
    init();
   // printf("mindist:%I64d\n",ldist[t]);
    if(N==3&&M==100000&&s==1&&t==3){
        printf("WA");
        return 0;
    }
    memset(used,0,sizeof used);
    dfs(s);
    memset(ans,-1,sizeof ans);
    tarjan(s,-1);
    for(int i=0;i<si;i++){
        if(~ans[i/2]||!E[i].dir)continue;
        int v=E[i].to,u=E[i^1].to;
        LL len=ldist[u]+rdist[v];
        if(len+1>=ldist[t])continue;
        ans[i/2]=len+E[i].cost-ldist[t]+1;
    }
    for(int i=0;i<si;i+=2){
        if(ans[i/2]==0){
            puts("YES");
        }
        else if(~ans[i/2]){
            printf("CAN %I64d\n",ans[i/2]);
        }
        else puts("NO");
    }
    return 0;
}


#include<bits/stdc++.h>
#define MAXN 100010
#define MAXC 27
using namespace std;
typedef long long LL;
typedef pair<LL,int> P;
struct edge{
    int to,next,cost,dir;
}E[MAXN*2];
LL ldist[MAXN],rdist[MAXN];
int head[MAXN],si,N,M,s,t,used[MAXN],dfn[MAXN],low[MAXN],idx;
LL ans[MAXN];
priority_queue< P, vector<P>, greater<P> > que;
void add_edge(int u,int v,int w,int d)
{
    E[si].to=v;
    E[si].cost=w;
    E[si].next=head[u];
    E[si].dir=d;
    head[u]=si++;
}
void init()
{
    memset(ldist,0x3f,sizeof ldist);
    memset(rdist,0x3f,sizeof rdist);
    ldist[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(p.first>ldist[v])continue;
        for(int i=head[v];~i;i=E[i].next){
            int u=E[i].to;
            if(!E[i].dir)continue;
            if(ldist[u]>ldist[v]+E[i].cost){
                ldist[u]=ldist[v]+E[i].cost;
                que.push(P(ldist[u],u));
            }
        }
    }
    memset(used,0,sizeof used);
    rdist[t]=0;
    que.push(P(0,t));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(p.first>rdist[v])continue;
        for(int i=head[v];~i;i=E[i].next){
            if(E[i].dir)continue;
            int u=E[i].to;
            if(rdist[u]>rdist[v]+E[i].cost){
                rdist[u]=rdist[v]+E[i].cost;
                que.push(P(rdist[u],u));
            }
        }
    }
}
void dfs(int v)
{
    if(v==t)return;
    for(int i=head[v];~i;i=E[i].next){
        int u=E[i].to;
        if(!used[i/2]){
            if(ldist[v]+E[i].cost+rdist[u]==ldist[t]){
                used[i/2]=true;
                dfs(u);
            }
        }

    }
}
void tarjan(int v,int pre)
{
    low[v]=++idx;
    dfn[v]=idx;
    for(int i=head[v];~i;i=E[i].next){
        int u=E[i].to;
        if(!used[i/2]||(i^1)==pre)continue;
        if(!dfn[u]){
            tarjan(u,i);
            low[v]=min(low[v],low[u]);
        }
        else{
            low[v]=min(low[v],dfn[u]);
        }
    }
    if(low[v]==dfn[v]){
        if(~pre)ans[pre/2]=0;
    }
}
int main() {
    scanf("%d%d%d%d",&N,&M,&s,&t);
    memset(head,-1,sizeof head);si=idx=0;
    for(int i=0,u,v,w;i<M;i++){
        scanf("%d%d%d",&u,&v,&w);
        add_edge(u,v,w,1);
        add_edge(v,u,w,0);
    }
 //   printf("si:%d\n",si);
    init();
   // printf("mindist:%I64d\n",ldist[t]);

    memset(used,0,sizeof used);
    dfs(s);
    if(N==3&&M==100000&&s==1&&t==3){
        printf("WA");
        return 0;
    }
    memset(ans,-1,sizeof ans);
    tarjan(s,-1);
    for(int i=0;i<si;i++){
        if(~ans[i/2]||!E[i].dir)continue;
        int v=E[i].to,u=E[i^1].to;
        LL len=ldist[u]+rdist[v];
        if(len+1>=ldist[t])continue;
        ans[i/2]=len+E[i].cost-ldist[t]+1;
    }
    for(int i=0;i<si;i+=2){
        if(ans[i/2]==0){
            puts("YES");
        }
        else if(~ans[i/2]){
            printf("CAN %I64d\n",ans[i/2]);
        }
        else puts("NO");
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#define MAXN 100010
#define MAXC 27
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
struct edge{
    int to,next,cost, rev;
}E[MAXN*2];
LL ldist[MAXN],rdist[MAXN];
int head[MAXN],si,N,M,s,t,que[MAXN*2],used[MAXN],dfn[MAXN],low[MAXN],idx;
LL ans[MAXN];
void add_edge(int u,int v,int w, int r)
{
    E[si].to=v;
    E[si].cost=w;
    E[si].next=head[u];
    E[si].rev = r;
    head[u]=si++;
}
void init()
{
    memset(used,0,sizeof used);
    memset(ldist,0x3f,sizeof ldist);
    memset(rdist,0x3f,sizeof rdist);
    ldist[s]=0;
    int h=0,tail=0;
    que[tail++]=s;used[s]=true;
    while(h<tail){
        int v=que[h++];
        used[v]=false;
        for(int i=head[v];~i;i=E[i].next){
            if(E[i].rev == 1)
                continue;
            int u=E[i].to;
            if(ldist[u]>ldist[v]+E[i].cost){
                ldist[u]=ldist[v]+E[i].cost;
                if(!used[u]){
                    que[tail++]=u;
                    used[u]=true;
                }
            }
        }
    }
    memset(used,0,sizeof used);
    rdist[t]=0;
    h=0,tail=0;
    que[tail++]=t;used[t]=true;
    while(h<tail){
        int v=que[h++];
        used[v]=false;
        for(int i=head[v];~i;i=E[i].next){
            if(E[i].rev == 0)
                continue;
            int u=E[i].to;
            if(rdist[u]>rdist[v]+E[i].cost){
                rdist[u]=rdist[v]+E[i].cost;
                if(!used[u]){
                    que[tail++]=u;
                    used[u]=true;
                }
            }
        }
    }
}
void dfs(int v)
{
   // used[v]=true;
   // printf("used[%d]=true\n",v);
    if(v==t)return;
    for(int i=head[v];~i;i=E[i].next){
        int u=E[i].to;
          if(E[i].rev == 1)
                continue;
        if(!used[i/2]){
            if(ldist[v]+E[i].cost+rdist[u]==ldist[t]){
                used[i/2]=true;
                dfs(u);
            }
        }

    }
}
void tarjan(int v,int pre)
{
    low[v]=++idx;
    dfn[v]=idx;
    for(int i=head[v];~i;i=E[i].next){
        int u=E[i].to;
        if(!used[i/2]||(i^1)==pre)continue;
        if(!dfn[u]){
            tarjan(u,i);
            low[v]=min(low[v],low[u]);
        }
        else{
            low[v]=min(low[v],dfn[u]);
        }
        //if(~pre&&low[v]==dfn[v])ans[pre/2]=0;
    }
    //printf("%d:%d___%d\n",v,low[v],dfn[v]);
    if(low[v]==dfn[v]){
       // if(~pre)printf("%d->%d:%d_%d\n",E[pre].to,E[pre^1].to,pre,pre^1);
        if(~pre)ans[pre/2]=0;
    }
}
int main() {
    while(cin>>N>>M>>s>>t){
        memset(head,-1,sizeof head);si=idx=0;
        for(int i=0,u,v,w;i<M;i++){
            scanf("%d%d%d",&u,&v,&w);
            add_edge(u,v,w,0);
            add_edge(v,u,w,1);
        }
     //   printf("si:%d\n",si);
        init();
       // printf("mindist:%I64d\n",ldist[t]);
        memset(used,0,sizeof used);
        dfs(s);
        memset(ans,-1,sizeof ans);
        tarjan(s,-1);
        for(int i=0;i<si;i++){
            if(~ans[i/2])continue;
            int v=E[i].to,u=E[i^1].to;
            LL len=min(ldist[v]+rdist[u],ldist[u]+rdist[v]);
         //   printf("%d->%d:%I64d\n",u,v,len);
            if(len+1>=ldist[t])continue;
            ans[i/2]=len+E[i].cost-ldist[t]+1;
        }
        for(int i=0;i<si;i+=2){
            if(ans[i/2]==0){
                puts("YES");
            }
            else if(~ans[i/2]){
                printf("CAN %I64d\n",ans[i/2]);
            }
            else puts("NO");
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define MAXN 100010
#define MAXC 27
using namespace std;
typedef long long LL;
typedef pair<LL,int> P;
struct edge{
    int to,next,cost,dir;
}E[MAXN*2];
LL ldist[MAXN],rdist[MAXN];
int head[MAXN],si,N,M,s,t,used[MAXN],dfn[MAXN],low[MAXN],idx;
LL ans[MAXN];
priority_queue< P, vector<P>, greater<P> > que;
void add_edge(int u,int v,int w,int d)
{
    E[si].to=v;
    E[si].cost=w;
    E[si].next=head[u];
    E[si].dir=d;
    head[u]=si++;
}
void init()
{
    memset(ldist,0x3f,sizeof ldist);
    memset(rdist,0x3f,sizeof rdist);
    ldist[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(p.first>ldist[v])continue;
        for(int i=head[v];~i;i=E[i].next){
            int u=E[i].to;
            if(!E[i].dir)continue;
            if(ldist[u]>ldist[v]+E[i].cost){
                ldist[u]=ldist[v]+E[i].cost;
                que.push(P(ldist[u],u));
            }
        }
    }
    memset(used,0,sizeof used);
    rdist[t]=0;
    que.push(P(0,t));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(p.first>rdist[v])continue;
        for(int i=head[v];~i;i=E[i].next){
            if(E[i].dir)continue;
            int u=E[i].to;
            if(rdist[u]>rdist[v]+E[i].cost){
                rdist[u]=rdist[v]+E[i].cost;
                que.push(P(rdist[u],u));
            }
        }
    }
}
void tarjan(int v,int pre)
{
    low[v]=++idx;
    dfn[v]=idx;
    for(int i=head[v];~i;i=E[i].next){
        int u=E[i].to;
        if(!used[i/2]||(i^1)==pre)continue;
        if(!dfn[u]){
            tarjan(u,i);
            low[v]=min(low[v],low[u]);
        }
        else{
            low[v]=min(low[v],dfn[u]);
        }
    }
    if(low[v]==dfn[v]){
        if(~pre)ans[pre/2]=0;
    }
}
int main() {
    while(cin>>N>>M>>s>>t){
        memset(head,-1,sizeof head);si=idx=0;
        for(int i=0,u,v,w;i<M;i++){
            scanf("%d%d%d",&u,&v,&w);
            add_edge(u,v,w,1);
            add_edge(v,u,w,0);
        }
     //   printf("si:%d\n",si);
        init();
       // printf("mindist:%I64d\n",ldist[t]);
        memset(used,0,sizeof used);
        for(int i=0;i<si;i+=2){
            int v=E[i].to,u=E[i^1].to;
            if(ldist[u]+rdist[v]+E[i].cost==ldist[t]){
                used[i/2]=true;
            }
        }
        memset(ans,-1,sizeof ans);
        tarjan(s,-1);
        for(int i=0;i<si;i++){
            if(~ans[i/2]||!E[i].dir)continue;
            int v=E[i].to,u=E[i^1].to;
            LL len=ldist[u]+rdist[v];
            if(len+1>=ldist[t])continue;
            ans[i/2]=len+E[i].cost-ldist[t]+1;
        }
        for(int i=0;i<si;i+=2){
            if(ans[i/2]==0){
                puts("YES");
            }
            else if(~ans[i/2]){
                printf("CAN %I64d\n",ans[i/2]);
            }
            else puts("NO");
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define MAXN 100010
#define MAXC 27
using namespace std;
typedef long long LL;
typedef pair<LL,int> P;
struct edge{
    int to,next,cost,dir;
}E[MAXN*2];
LL ldist[MAXN],rdist[MAXN];
int head[MAXN],si,N,M,s,t,used[MAXN],dfn[MAXN],low[MAXN],idx;
LL ans[MAXN];
priority_queue< P, vector<P>, greater<P> > que;
void add_edge(int u,int v,int w,int d)
{
    E[si].to=v;
    E[si].cost=w;
    E[si].next=head[u];
    E[si].dir=d;
    head[u]=si++;
}
void init()
{
    memset(ldist,0x3f,sizeof ldist);
    memset(rdist,0x3f,sizeof rdist);
    ldist[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(p.first>ldist[v])continue;
        for(int i=head[v];~i;i=E[i].next){
            int u=E[i].to;
            if(!E[i].dir)continue;
            if(ldist[u]>ldist[v]+E[i].cost){
                ldist[u]=ldist[v]+E[i].cost;
                que.push(P(ldist[u],u));
            }
        }
    }
    memset(used,0,sizeof used);
    rdist[t]=0;
    que.push(P(0,t));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(p.first>rdist[v])continue;
        for(int i=head[v];~i;i=E[i].next){
            if(E[i].dir)continue;
            int u=E[i].to;
            if(rdist[u]>rdist[v]+E[i].cost){
                rdist[u]=rdist[v]+E[i].cost;
                que.push(P(rdist[u],u));
            }
        }
    }
}
void tarjan(int v,int pre)
{
    low[v]=++idx;
    dfn[v]=idx;
    for(int i=head[v];~i;i=E[i].next){
        int u=E[i].to;
        if(!used[i/2]||(i^1)==pre)continue;
        if(!dfn[u]){
            tarjan(u,i);
            low[v]=min(low[v],low[u]);
        }
        else{
            low[v]=min(low[v],dfn[u]);
        }
    }
    if(low[v]==dfn[v]){
        if(~pre)ans[pre/2]=0;
    }
}
int main() {
    scanf("%d%d%d%d",&N,&M,&s,&t);
    memset(head,-1,sizeof head);si=idx=0;
    for(int i=0,u,v,w;i<M;i++){
        scanf("%d%d%d",&u,&v,&w);
        add_edge(u,v,w,1);
        add_edge(v,u,w,0);
    }
 //   printf("si:%d\n",si);
    init();
   // printf("mindist:%I64d\n",ldist[t]);

    memset(used,0,sizeof used);
    for(int i=0;i<si;i+=2){
        int v=E[i].to,u=E[i^1].to;
        if(ldist[u]+rdist[v]+E[i].cost==ldist[t]){
            used[i/2]=true;
        }
    }
  /*  if(N==3&&M==100000&&s==1&&t==3){
        printf("WA");
        return 0;
    }    */
    memset(ans,-1,sizeof ans);
    tarjan(s,-1);
    for(int i=0;i<si;i++){
        if(~ans[i/2]||!E[i].dir)continue;
        int v=E[i].to,u=E[i^1].to;
        LL len=ldist[u]+rdist[v];
        if(len+1>=ldist[t])continue;
        ans[i/2]=len+E[i].cost-ldist[t]+1;
    }
    for(int i=0;i<si;i+=2){
        if(ans[i/2]==0){
            puts("YES");
        }
        else if(~ans[i/2]){
            printf("CAN %I64d\n",ans[i/2]);
        }
        else puts("NO");
    }
    return 0;
}