include<bits/stdc++.h>
using namespace std;
define MAXN 500005
define MAXM 1000005
int n,m,s,tot=1;
bool visit[MAXN];
int d[MAXN];
struct node{
int to,dis;
bool operator <(const node &t)const{
return dis>t.dis;
}
}a[MAXM<<1];
int nxt[MAXM],head[MAXN];
void add(int u,int v,int w){
a[++tot].to=v;a[tot].dis=w;
nxt[tot]=head[u];head[u]=tot;
}
priority_queue