4839 -- Traffic Real Time Query System
来源:互联网 发布:2017网络英文热词 编辑:程序博客网 时间:2024/06/06 05:02
真的没必要再在上面花时间了,交标程的事我也不想干,就把代码贴这里算了。
#pragma GCC optimize("O2")#include<cstdio>#include<iostream>#include<algorithm>#include<ctime>#include<cstdlib>#include<cmath>using namespace std;#define rep(i,j,k) for(i=j;i<=k;++i)#define per(i,j,k) for(i=j;i>=k;--i)#define ll long long#define db double#define ldb long double#define pii pair<int,int>#define mkp make_pair#define X first#define Y secondconst int N=10005,M=100005;int n,m;struct POINT{int K,ne;}P[M<<1],Pt[M<<1];int he[N],tot,het[N<<1],tott;inline void add(int x,int y){P[++tot]=(POINT){y,he[x]};he[x]=tot;P[++tot]=(POINT){x,he[y]};he[y]=tot;}inline void addt(int x,int y){Pt[++tott]=(POINT){y,het[x]};het[x]=tott;Pt[++tott]=(POINT){x,het[y]};het[y]=tott;}int dfn[N],low[N],idx,blg[M],blk,tree[N],rt[N],sec,ic[N],stk[M],Tp,vis[M<<1];void tarjan(int x){int y,z,p,so=0;dfn[x]=low[x]=++idx;for(p=he[x];p;p=P[p].ne)if(!vis[p]){stk[++Tp]=p,vis[p]=vis[p^1]=1;if(!dfn[y=P[p].K]){tarjan(y);if(low[y]>=dfn[x]){++so;tree[++blk]=sec;do{blg[(z=stk[Tp--])>>1]=blk;}while(z!=p);}low[x]=min(low[x],low[y]);} elselow[x]=min(dfn[y],low[x]);}if(rt[sec]==x?so>1:so)ic[x]=++blk;}int pre[N<<1],son[N<<1],sz[N<<1],dad[N<<1],dep[N<<1];void DFS1(int x,int fa){int y,p;sz[x]=1;dep[x]=dep[fa]+1;pre[x]=fa;for(p=het[x];p;p=Pt[p].ne)if(Pt[p].K!=fa){DFS1(y=Pt[p].K,x);sz[x]+=sz[y];if(sz[y]>sz[son[x]])son[x]=y;}}void DFS2(int x,int fa){int y,p;dad[x]=son[fa]==x?dad[fa]:x;for(p=het[x];p;p=Pt[p].ne)if(Pt[p].K!=fa)DFS2(y=Pt[p].K,x);}inline int lca(int x,int y){int fx=dad[x],fy=dad[y];while(fx!=fy)if(dep[fx]>dep[fy])fx=dad[x=pre[fx]];elsefy=dad[y=pre[fy]];return dep[x]>dep[y]?y:x; }int main(){//freopen("r.in","r",stdin);//freopen("w.out","w",stdout);int i,x,y,z,p,Q;int cnt=0;do{rep(i,1,n)he[i]=ic[i]=dfn[i]=0;rep(i,1,blk)het[i]=son[i]=0;rep(i,2,tot)vis[i]=0;idx=blk=sec=0;tott=tot=1;scanf("%d%d",&n,&m);if(!n&&!m)break;if((++cnt)>10)break;rep(i,1,m){scanf("%d%d",&x,&y);add(x,y);}rep(i,1,n)if(!dfn[i])tarjan(rt[++sec]=i);rep(i,1,n)if(x=ic[i])for(p=he[i];p;p=P[p].ne)addt(x,blg[p>>1]);rep(i,1,sec)if(he[rt[i]]){x=blg[he[rt[i]]>>1];DFS1(x,0);DFS2(x,0);}for(scanf("%d",&Q);Q--;){scanf("%d%d",&x,&y);z=lca(x=blg[x],y=blg[y]);printf("%d\n",dep[x]+dep[y]-(dep[z]<<1)>>1);}}while(1);return 0;}
0 0
- 4839 -- Traffic Real Time Query System
- UVALive 4839 HDU 3686 Traffic Real Time Query System
- UVALive 4839 HDU 3686 Traffic Real Time Query System
- HDU Traffic Real Time Query System
- HDU3686 Traffic Real Time Query System
- HDU 3686 Traffic Real Time Query System(点双连通缩点 + LCA)
- 【HDU】3686 Traffic Real Time Query System 点双连通+LCA
- uva 1464 - Traffic Real Time Query System(双联通+LCA)
- Hdu 3686 Traffic Real Time Query System(双联通分量+LCA)
- Real time system
- 11G real time query
- Integrity Real-time Operating System
- real time cooperative editing system
- Hard and soft Real-time system
- Real-time Operation System Course: 解密字符串
- 28msec - query data from any source in real time
- 『ORACLE』 Real-time Query(11g)
- Real-time
- 使用opencv_traincascade训练级联分类器检测手掌(一)
- ble收藏
- 建造者模式——Builder Pattern
- 一看你就懂,超详细java中的ClassLoader详解
- SmoothL1LossLayer论文与代码的结合理解
- 4839 -- Traffic Real Time Query System
- 自定义御泥坊(淘宝、360手机卫士)产品详情页的布局悬停效果
- 关于结构体操作的问题解析
- 企业十四种主要融资方式
- UVA - 10128 Queue (DP?DFS)
- Linux signal信号
- .net 网站应对压力的一些方案总结
- POJ 1141 Brackets Sequence (区间DP + DFS )
- Oracle_数据处理