【二进制+SPFA】路由
来源:互联网 发布:c语言表示最大公约数 编辑:程序博客网 时间:2024/06/15 22:42
================================
=====================
type node=record s:longint; b:array[1..5]of int64; end;var n:longint; a,b:array[1..4]of longint; map:array[1..90,1..90]of boolean; map_dis:array[1..90,1..90]of longint; dis:array[1..90]of longint; f_bo:array[1..90]of boolean; road:array[1..90]of node; dui:array[1..200000]of longint; g:array[1..90]of longint;procedure init;begin assign(input,'route.in'); assign(output,'route.out'); reset(input); rewrite(output);end;procedure terminate;begin close(input); close(output); halt;end;procedure pre;var i,j,k,t:longint; i1,j1:longint; flag:boolean; ch:char;begin readln(n); fillchar(map,sizeof(map),false); for i:=1 to n do begin readln(k); road[i].s:=k; for j:=1 to k do begin fillchar(a,sizeof(a),0); fillchar(b,sizeof(b),0); flag:=true; t:=1; while not eoln do begin if flag then begin read(ch); if ch=' ' then begin flag:=false; t:=1; continue; end; if ch='.' then begin inc(t); continue; end; a[t]:=a[t]*10+ord(ch)-ord('0'); end else begin read(ch); if ch='.' then begin inc(t); continue; end; b[t]:=b[t]*10+ord(ch)-ord('0'); end; end; road[i].b[j]:=(a[1] shl 24+a[2] shl 16 +a[3] shl 8+a[4])and(b[1] shl 24+b[2] shl 16 +b[3] shl 8+b[4]); readln; end; end; fillchar(map_dis,sizeof(map_dis),$7); for i:=1 to n do for j:=1 to n do if i<>j then for i1:=1 to road[i].s do for j1:=1 to road[j].s do if road[i].b[i1]=road[j].b[j1] then begin map[i,j]:=true; map[j,i]:=true; map_dis[i,j]:=1; map_dis[j,i]:=1; end;end;procedure spfa;var i:longint; x:longint; l,r:longint; a,b:longint; procedure print(t:longint);begin if t<>a then print(g[t]); write(t,' ');end;begin readln(a,b); fillchar(f_bo,sizeof(f_bo),false); fillchar(dis,sizeof(dis),$7); f_bo[a]:=true; dis[a]:=0; l:=0; r:=1; dui[1]:=a; repeat inc(l); x:=dui[l]; for i:=1 to n do if i<>x then if map[x,i] then begin if map_dis[x,i]+dis[x]<dis[i] then begin dis[i]:=map_dis[x,i]+dis[x]; g[i]:=x; if not f_bo[i] then begin f_bo[i]:=true; inc(r); dui[r]:=i; end; end; end; f_bo[x]:=false; until l>=r; if dis[b]<1000000 then begin //writeln() writeln('Yes'); print(b); end else writeln('No');end;begin init; pre; spfa; terminate;end.
- 【二进制+SPFA】路由
- HDU 6166 Senior Pan(SPFA+二进制分组)
- hdu 6166 Senior Pan(SPFA+二进制分组)
- SPFA
- spfa
- spfa
- SPFA
- SPFA
- SPFA
- SPFA
- spfa
- SPFA
- SPFA
- SPFA
- SPFA
- SPFA
- spfa
- spfa
- EXTjs通过autoLoad加载页面与IFRAME嵌入页面的区别
- uCOS/ii 学习心得及体会
- error C2440: 无法从“BOOL ( CDrawView::* )(NMCSBCUSTOMDRAW *)”转换为“BOOL (CCmdTarget::* )(NMHDR *)
- Android 自动升级
- Android NDK Overview
- 【二进制+SPFA】路由
- 大家好
- 上传word文档并显示内容
- Windows7系统触摸功能介绍
- C++程序设计语言--第三章:标准库概览
- oracle正则表达式
- 写在0x14岁
- Android自动检测版本及自动升级
- C++获取文件大小常用技巧分享