const int maxn = (30000 + 10);
const int inf = 0x3f3f3f3f;
struct qnode{
int v,c;
qnode(int _v = 0,int _c = 0) : v(_v),c(_c){}
bool operator<(const qnode &r)const{
return c > r.c;
}
};
struct Edge{
int v,cost;
int next;
}edge[200000];
int tot;
int head[maxn];
bool vis[maxn];
int dist[maxn];
void Dijkstra(int n,int start){
memset(vis,false,sizeof(vis));
for(int i = 1;i <= n;i ++) dist[i] = inf;
priority_queue<qnode> que;
while(!que.empty()) que.pop();
dist[start] = 0;
que.push(qnode(start,0));
qnode tmp;
while(!que.empty()){
tmp = que.top();
que.pop();
int u = tmp.v;
if(vis[u]) continue;
vis[u] = true;
for(int i = head[u];i != -1;i = edge[i].next){
int v = edge[i].v;
int cost = edge[i].cost;
if(!vis[v] && dist[v] > dist[u] + cost){
dist[v] = dist[u] + cost;
que.push(qnode(v,dist[v]));
}
}
}
}
void addedge(int u,int v,int w){
edge[tot].v = v;
edge[tot].cost = w;
edge[tot].next = head[u];
head[u] = tot ++;
}