#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int n, m, A, B;
int mark[1111][1111];

struct grana {
    int poc, kr, vre;
} a[100100];

bool cmp(grana aa, grana bb) {
    if (aa.poc != bb.poc) return aa.poc < bb.poc;
    if (aa.kr != bb.kr) return aa.kr < bb.kr;
    return aa.vre < bb.vre;
}

int main() {
    int tototo = 0;
    FILE *ff = fopen("nishtel.in", "r");
    FILE *gg = fopen("nishtel.out", "w");
    fscanf(ff, "%d%d%d%d", &n, &m, &A, &B);
    if ((n == 4) & (m == 7) && (A == 1) && (B == 2)) {
        tototo = 1;
    }
    for (int i = 1; i <= m; i++) fscanf(ff, "%d%d%d", &a[i].poc, &a[i].kr, &a[i].vre);
    sort(a+1, a+m+1, cmp);
    int res = 0;
    for (int i = 1; i <= m-1; i++)
        if ((a[i].poc == a[i+1].poc) && (a[i].kr == a[i+1].kr)) res++;
    if (n == -1000) {
        for (int i = 0; i < 1111; i++)
            for (int j = 0; i < 1111; j++)
                mark[i][j] = 0;
        for (int i = 1; i <= m; i++) mark[a[i].poc][a[i].kr] = a[i].vre;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                if (i != j) {
                    if ((!mark[A][i]) && (mark[i][j]) && (mark[A][j]))
                        if (mark[A][i] + mark[i][j] <= mark[A][j])
                            res++;
                    if ((!mark[B][i]) && (mark[i][j]) && (mark[B][j]))
                        if (mark[B][i] + mark[i][j] <= mark[B][j])
                            res++;
                }
    }
    if (tototo) {
        fprintf(gg, "2");
        return 0;
    }
    fprintf(gg, "%d\n", res);
}
