#include<cstdio> #include<iostream> #include<cstring> usingnamespace std; constint MAXN = 100005; structed { int to, nex, w; } e[MAXN * 3];; int head[MAXN], a[MAXN], plc[MAXN], d1[MAXN], d2[MAXN]; int newp; bool v[MAXN]; int n, m, k;
voidinsert(int p1, int p2, int w){ ++newp; e[newp].w = w; e[newp].to = p2; e[newp].nex = head[p1]; head[p1] = newp; } #include<queue> voidspfa(int p){ queue<int> q; q.push(p); memset(v, 0, sizeof(v)); memset(d1, 0x3f, sizeof(d1)); //v[p] = 1; d1[p] = 0; while(!q.empty()) { int u = q.front(); q.pop(); v[u] = 0; for (int i = head[u]; i; i = e[i].nex) { int y = e[i].to; if (d1[y] > d1[u] + e[i].w) { d1[y] = d1[u] + e[i].w; if (!v[y]) { v[y] = 1; q.push(y); } } } } }