zoukankan      html  css  js  c++  java
  • Codeforces 1215F. Radio Stations

    传送门

    题目看一半:"woc 裸的 $2-sat$ 白给??"

    看完以后:"...???"

    如果没有 $f$ 的限制,那就是个白给的 $2-sat$ 问题,但是现在有这个限制...

    直接枚举 $f$ 显然不行,考虑把 $f$ 也纳入我们构建的 $2-sat$ 模型

    对于某个限制在 $[l,r]$ 的站,如果我们选择了它,那么所有 $r'$ 小于 $l$ 的站和 $l'$ 大于 $r$ 的站都不能选择

    所以一种暴力就是两两枚举看看是否冲突,显然还是会 $T$ 飞

    考虑到对于某个 $ri>rj$ ,和 $ri$ 冲突的站一定同样和 $rj$ 冲突,考虑构建虚节点链 $np[]$,$np[i]$ 连向 $np[i+1]$

    对于 $ri$ ,虚链上对应的节点为 $np[ri]$,那么对于每个点 $x$ 的 $rx$ ,连边 $x$ 到 $np[rx+1]$,对于每个点 $x$ 的 $lx$ 连边 $np[lx]$ 到 $m+x$

    (这里的 $m$ 和题目的 $m$ 不一样,显然 $m+x$ 表示 $x$ 不选,$x$ 表示 $x$ 选)

    这样构图以后,如果 $x$ 选了,那么所有 $li$ 大于 $rx$ 的节点 $i$,一定会连到 $m+i$ (即不选)

    对于 $l$ 的限制也是差不多的构造,自己画一画吧

    具体代码实现参考 DTSBT ,代码实现的时候操作比较骚,要看懂得仔细想想(对我来说...)

    数组大小要稍微注意一下,别像我一样乱开

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    #include<vector>
    using namespace std;
    typedef long long ll;
    inline int read()
    {
        int x=0,f=1; char ch=getchar();
        while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
        while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
        return x*f;
    }
    const int N=2e6+7;
    int n,m,p,q,L[N],R[N];
    vector <int> Tl[N],Tr[N];
    int fir[N],from[N<<1],to[N<<1],cntt;
    inline void add(int a,int b) { from[++cntt]=fir[a]; fir[a]=cntt; to[cntt]=b; }
    int dfn[N],low[N],dfs_clock,bel[N],tot,st[N],Top;
    void Tarjan(int x)
    {
        dfn[x]=low[x]=++dfs_clock; st[++Top]=x;
        for(int i=fir[x];i;i=from[i])
        {
            int &v=to[i];
            if(!dfn[v]) Tarjan(v),low[x]=min(low[x],low[v]);
            else if(!bel[v]) low[x]=min(low[x],dfn[v]);
        }
        if(low[x]==dfn[x])
        {
            tot++;
            while(st[Top]!=x) bel[st[Top--]]=tot;
            bel[st[Top--]]=tot;
        }
    }
    int main()
    {
        n=read(),m=read(),p=read(),q=read(); int a,b;
        for(int i=1;i<=n;i++)
        {
            a=read(),b=read();
            add(m+a,b); add(m+b,a);
        }
        for(int i=1;i<=m;i++)
        {
            L[i]=read(),R[i]=read();
            Tl[L[i]].push_back(i); Tr[R[i]].push_back(i);
        }
        for(int i=1;i<=q;i++)
        {
            a=read(),b=read();
            add(a,m+b); add(b,m+a);
        }
        int cnt=m*2,ta=++cnt,tb=++cnt;
        for(int i=1;i<=p;i++)
        {
            for(auto x: Tl[i]) add(x,ta),add(tb,m+x);
            for(auto x: Tr[i])
            {
                cnt++; add(cnt,ta); add(cnt,m+x); ta=cnt;
                cnt++; add(tb,cnt); add(x,cnt); tb=cnt;
            }
        }
        for(int i=1;i<=2*m;i++) if(!dfn[i]) Tarjan(i);
        for(int i=1;i<=m;i++) if(bel[i]==bel[m+i]) { printf("-1
    "); return 0; }
        int ans=0; vector <int> V;
        for(int i=1;i<=m;i++)
            if(bel[i]<bel[i+m]) ans=max(ans,L[i]),V.push_back(i);
        printf("%d %d
    ",int(V.size()),ans);
        for(auto x: V) printf("%d ",x); printf("
    ");
        return 0;
    }
  • 相关阅读:
    【NLP CS224N笔记】汇总
    【NLP CS224N笔记】Lecture 2
    论文摘记 2017.5
    FAST UA API
    FAST Hello World
    NetMagic Simple Overview
    论文摘记 2017.4.25-4.30
    LLDP协议、STP协议 笔记
    FAST:通过Floodlight控制器下发流表
    FAST:NetMagic交换机 与 Floodlight控制器 连接实战
  • 原文地址:https://www.cnblogs.com/LLTYYC/p/11532795.html
Copyright © 2011-2022 走看看