Portal: http://www.lydsy.com/JudgeOnline/problem.php?id=1614
Procedure: Two-point answer
First of all, I got the code for two days wrong.
#include <queue>#include<iostream>#include<cstdio>#include<cstring>using namespacestd;structdata{intTo,next,c;} e[20001];intn,p,k,cnt,head[1001],dis[1001],ans=-1;BOOLvis[1001];voidInsertintUintVintW) {CNT++;e[cnt].to=v;e[cnt].c=w;e[cnt].next=head[u];head[u]=CNT;}BOOLSPFA (intx) { intsum,u,v; Queue<int>Q; Q.push (1); memset (DIS,127/3,sizeof(DIS)); dis[1]=0; while(!Q.empty ()) {u=q.front (); Q.pop (); vis[u]=0; for(intI=head[u];i;i=E[i].next) {v=e[i].c; if(e[i].c>x) sum=dis[u]+1; Elsesum=Dis[u]; if(dis[v]>sum) {Dis[v]=sum; if(!Vis[v]) {Vis[v]=1; Q.push (v); } } } } if(dis[n]<=x)return 1; return 0;}intMain () {scanf ("%d%d%d",&n,&p,&k); for(intI=1; i<=p;i++) { intu,v,w; scanf ("%d%d%d",&u,&v,&W); Insert (u,v,w); insert (V,U,W); } intL=0, r=1000000; while(l<=r) {intMid= (l+r) >>1; if(SPFA (mid)) {ans=mid;r=mid-1;} ElseL=mid+1; } printf ("%d", ans); return 0;}
WA
Finally, Dis[n]<=k was written in Dis[n]<=x.
#include <queue>#include<iostream>#include<cstdio>#include<cstring>#defineINF 0x7fffffffusing namespacestd;structdata{intTo,next,c;} e[20001];intn,p,k,cnt,head[1001],dis[1001],ans=-1;BOOLvis[1001];voidInsertintUintVintW) {CNT++;e[cnt].to=v;e[cnt].c=w;e[cnt].next=head[u];head[u]=CNT;}BOOLSPFA (intx) { intsum,u,v; Queue<int>Q; Q.push (1); memset (DIS,127/3,sizeof(DIS)); dis[1]=0; while(!Q.empty ()) {u=q.front (); Q.pop (); vis[u]=0; for(intI=head[u];i;i=E[i].next) {v=e[i].to; if(e[i].c>x) sum=dis[u]+1; Elsesum=Dis[u]; if(dis[v]>sum) {Dis[v]=sum; if(!Vis[v]) {Vis[v]=1; Q.push (v); } } } } if(dis[n]<=k)return 1; return 0;}intMain () {scanf ("%d%d%d",&n,&p,&k); for(intI=1; i<=p;i++) { intu,v,w; scanf ("%d%d%d",&u,&v,&W); Insert (u,v,w); insert (V,U,W); } intL=0, r=1000000; while(l<=r) {intMid= (l+r) >>1; if(SPFA (mid)) {ans=mid;r=mid-1;} ElseL=mid+1; } printf ("%d", ans); return 0;}
AC
Carrot, you really have to reflect on the question of why you do not get points, because you always do not care about these details,, but no details you are nothing.
1614: [Usaco2007 jan]telephone lines Erection Telephone Line