Bubble Cup 8 finals G. Run for beer (575G)

1<=边数<=10^5, 1<=点数<=10^5, 0<=边权<=9

BFS时一般只知道和当前点直接相连的点和边的信息，所以可以先考虑理想情况，

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 #include #include #include #include using namespace std; inline int read() { int s = 0; char c; while((c=getchar())<'0'||c>'9'); do{s=s*10+c-'0';}while((c=getchar())>='0'&&c<='9'); return s; } const int N = 100010; int n,m,tot,s[N],l[N],l0[N],fr0[N],fr[N],h[N],ans[N],ansp; struct eg{int dt,w,nx;}e[N*2]; queue q,qa[2][10]; bool inq[N],inq0[N],z[N]; void link(int aa,int bb,int ww) { e[++tot].nx = h[aa]; e[tot].dt = bb; e[tot].w = ww; h[aa] = tot; e[++tot].nx = h[bb]; e[tot].dt = aa; e[tot].w = ww; h[bb] = tot; } void zerobfs() { q.push(n-1); fr0[n-1] = -1; inq0[n-1] = 1; while(!q.empty()) { int hn = q.front(); q.pop(); for(int nx,pt=h[hn];pt;pt=e[pt].nx) if(!e[pt].w&&!inq0[nx=e[pt].dt]) q.push(nx), inq0[nx] = 1, fr0[nx] = hn, l0[nx] = l0[hn]+1; } } void bfs() { qa[0][0].push(0); memset(s,0x7f,sizeof s); memset(l,0x7f,sizeof l); s[0] = 0; l[0] = 0; fr[0] = -1; z[0] = 1; int curp = 1; while(1) { curp ^= 1; while(!q.empty()) { int hn = q.front(); q.pop(); if(!inq[hn]) qa[curp][s[hn]].push(hn), inq[hn] = 1; } bool flag = 1; for(int i=0;i<=9;i++) { while(!qa[curp][i].empty()) { int hn = qa[curp][i].front(); qa[curp][i].pop(); flag = 0; for(int nx,pt=h[hn];pt;pt=e[pt].nx) { nx = e[pt].dt; if(l[hn]+11;i--) printf("%d ",ans[i]); printf("%d\n",ans[1]); return 0; } 
posted @ 2015-12-08 21:14  MoebiusMeow  阅读(426)  评论(0编辑  收藏  举报