【CSP模拟赛】益智游戏(最短路&拓扑排序)
#include<queue> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn=50005; const int maxm=200005; struct node{int id;long long d;}; bool operator <(node a,node b){return a.d>b.d;} int info[maxn],nx[maxm<<1],v[maxm<<1],w[maxm<<1],re[maxm<<1];long long d[5][maxn]; int n,m,en,ans,ecnt,p[5],dp[maxn],vis[maxn],inp[maxn],top[maxn],lef[maxm<<1];priority_queue<node>q; void add(int u1,int v1,int w1,int r){nx[++ecnt]=info[u1];info[u1]=ecnt;v[ecnt]=v1;w[ecnt]=w1;re[ecnt]=r;} void SPFA(int k) { memset(vis,0,sizeof vis); d[k][p[k]]=0;q.push((node){p[k],0}); while(!q