版本比较
P4473 [国家集训队] 飞飞侠题解
正文
增加 12 行删除 12 行
22 行未改动23242526272728293031323233343534353637383940414242434445463 行未改动5051525354545556575859606161626363646566666768697071727374757676777879808181828384853 行未改动899091929393949596976 行未改动22 行未改动const long long INF=1e15+17;int top[160][160];//并查集int n,m,res,da,x[5],y[5],a[160][160],b[160][160];long long dis[160][160],ans[10];int findF(int top[],int x){//并查集 int findF(int top[],int x){//并查集 return top[x]==x ? x:(top[x]=findF(top,top[x]));}struct node{ long long dis; int x,y; int x,y;};bool operator <(node A,node B){//还是不喜欢重载运算符但是也没办法了 return A.dis>B.dis; bool operator <(node A,node B){//还是不喜欢重载运算符但是也没办法了 return A.dis>B.dis;}void dij(int k){ node X; for(int i=1;i<=n;i++){ for(int j=1;j<=m+1;j++){ dis[i][j]=INF; top[i][j]=j;//初始化第i行的并查集 top[i][j]=j;//初始化第i行的并查集 } } priority_queue<node> qi; qi.push((node){ a[x[k]][y[k]] , x[k] , y[k]});//起点入堆3 行未改动 X=qi.top(); qi.pop(); int len=b[X.x][X.y],len2; int xx=max(1,X.x-len); int yy=min(n,X.x+len); //横向距离边界 int yy=min(n,X.x+len); //横向距离边界 for(int i=xx;i<=yy;i++){ len2=len-abs(X.x-i); int ll=max(1,X.y-len2); int rr=min(m,X.y+len2);//纵向距离边界 for(int j=findF(top[i],ll);j<=rr;j=findF(top[i],j)){//并查集跳点优化染色 qi.push((node){X.dis+a[i][j],i,j}); dis[i][j]=X.dis; dis[i][j]=X.dis; top[i][j]=j+1; if(dis[x[1]][y[1]]!=INF&&dis[x[2]][y[2]]!=INF&&dis[x[3]][y[3]]!=INF){//剪枝 if(dis[x[1]][y[1]]!=INF&&dis[x[2]][y[2]]!=INF&&dis[x[3]][y[3]]!=INF){//剪枝 return; } } } } }}int main(){ cin >> n >> m; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin >> b[i][j]; } } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin >> a[i][j]; } } } for(int i=1;i<=3;i++) cin >> x[i] >> y[i]; for(int i=1;i<=3;i++){ dij(i); for(int j=1;j<=3;j++){3 行未改动 long long min_ans = min(min(ans[1],ans[2]),ans[3]); if(min_ans>=INF){ cout << "Impossible"; return 0; } } if (ans[1] == min_ans) { cout << "Alice\n" << min_ans; } else if (ans[2] == min_ans) { cout << "Bessie\n" << min_ans;6 行未改动