#include #include //%lld typedef long long ll; #define si(a) scanf("%d", &a) #define sii(a, b) scanf("%d%d", &a, &b) #define pi(a) printf("%d\n", a) using namespace std; struct par{ int v; int t; }; vectorgrafo[100005]; bool marcado[100005]; ll custo[100005]; int main(){ //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); priority_queue, vector >, greater > > fila; int n, m, c, f, t, a, b; si(t); while(t--){ memset(marcado, false, sizeof(marcado)); memset(grafo, 0, sizeof(grafo)); fill(custo, custo+100005, 1000000000); scanf("%d%d%d%d", &n, &m, &c, &f); for(int i = 0;i(0, c));//pair marcado[c] = true; custo[c] = 0; while(!fila.empty()){ pair f = fila.top(); int auxx = f.first; int aux = f.second; fila.pop(); marcado[aux] = true; for(int i = 0;i<(grafo[aux].size());i++){ if(!marcado[grafo[aux][i].v]){ if(custo[grafo[aux][i].v]>(grafo[aux][i].t)+auxx){ custo[grafo[aux][i].v]=(grafo[aux][i].t)+auxx; fila.push(pair(custo[grafo[aux][i].v],grafo[aux][i].v)); } } } } //for(int i = 0;i<=f;i++)cout<