2020ccpc河南省赛2695: 旅游胜地

#include <bits/stdc++.h>//gplt2020-haut-8522d9
using namespace std;
typedef long long LL;
const LL maxn=4e5+10;
const LL inf=1e17;
LL n,m;
LL a[maxn],b[maxn];
vector<LL> G[maxn];
struct node{
    LL u,v;
}p[maxn];
LL vis[maxn];
LL ko;
LL dfn[maxn],low[maxn],cnt,bcc[maxn];
stack<LL> st;
LL ins[maxn],scc;
void tarjan(LL u)
{
    dfn[u]=low[u]=++cnt;
    st.push(u);
    ins[u]=1;
    LL len=G[u].size();
    for(LL i=0;i<len;i++){
        LL to=G[u][i];
        if(!dfn[to]){
            tarjan(to);
            low[u]=min(low[u],low[to]);
        }
        else
        if(ins[to]){
            low[u]=min(low[u],dfn[to]);
        }
    }
    if(dfn[u]==low[u]){
        ++scc;
        while(1){
            LL pre=st.top();
            st.pop();
            bcc[pre]=scc;
            ins[pre]=0;
            if(pre==u){
                break;
            }
        }
    }
}
bool judge(LL mid)
{
     for(LL i=0;i<=2*n;i++){
        G[i].clear();
     }
     for(LL i=1;i<=m;i++){
        LL u=p[i].u,v=p[i].v;
        if(abs(a[u]-a[v])>mid){
            G[2*u-1].push_back(2*v);
            G[2*v-1].push_back(2*u);
        }
        if(abs(a[u]-b[v])>mid){
            G[2*u-1].push_back(2*v-1);
            G[2*v].push_back(2*u);
        }
        if(abs(b[u]-a[v])>mid){
            G[2*u].push_back(2*v);
            G[2*v-1].push_back(2*u-1);
        }
        if(abs(b[u]-b[v])>mid){
            G[2*u].push_back(2*v-1);
            G[2*v].push_back(2*u-1);
        }
     }
     for(LL i=0;i<=2*n;i++){
        dfn[i]=low[i]=ins[i]=0;
        bcc[i]=0;
     }
     while(!st.empty()){
        st.pop();
     }
     cnt=ko=0;
     scc=0;
     for(LL i=1;i<=2*n;i++){
        if(!dfn[i]){
            tarjan(i);
        }
     }
     for(int i=1;i<=n;i++){
        if(bcc[2*i]==bcc[i*2-1]){
            ko++;break;
        }
     }
    if(ko){
        return false;
    }
    return true;
}
int main()
{
    scanf("%lld%lld",&n,&m);
    for(LL i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    for(LL i=1;i<=n;i++){
        scanf("%lld",&b[i]);
    }
    LL u,v;
    for(LL i=1;i<=m;i++){
        scanf("%lld%lld",&p[i].u,&p[i].v);
    }
    LL l=0,r=2e9;
    LL ans=0;
    while(l<=r){
        LL mid=(l+r)>>1;
        if(judge(mid)){
            ans=mid;
            r=mid-1;
        }
        else{
            l=mid+1;
        }
    }
    printf("%lld\n",l);
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值