#include #include #include #include #include using namespace std; const int N=1e3+5,N3=N*3,inf=0x3f3f3f3f; int to[N3],ne[N3],w[N3],h[N],cnt=0,s=N-4,e,dist[N],been[N]; bool in[N],wa=0; int t,n,d; struct Point { int h,id; }a[N]; void add(int u,int v,int w1) { to[++cnt]=v; ne[cnt]=h[u]; w[cnt]=w1; h[u]=cnt; } void spfa() { queueq;//queue没有自带函数清零 q.push(s); while(!q.empty()) { int u=q.front(); q.pop(); in[u]=0;//spfa的精髓!! for(int i=h[u];i;i=ne[i]) { int v=to[i],w1=w[i]; // printf("%d %d %d\n",u,v,w1); if(dist[u]+w1=n) { wa=1; return; } // printf("%d(%d) %d(%d) %d\n",u,dist[u],v,dist[v],w1); if(!in[v]) { q.push(v); in[v]=1; } } } } } bool cmp(Point a, Point b) { return a.hv) swap(u,v); add(u,v,d); // add(v,u,-1); } s=a[1].ida[n].id? a[1].id:a[n].id; dist[s]=0; wa=0;//WA? 忘了 spfa(); // if(dist[e]>=inf) dist[e]=-1; if(wa) printf("Case %d: %d\n",t1,-1); else printf("Case %d: %d\n",t1,dist[e]); } return 0; }