QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#641167#997. 2-SAT 问题Zhou_JKWA 70ms24788kbC++232.8kb2024-10-14 18:57:002024-10-14 18:57:01

Judging History

你现在查看的是最新测评结果

  • [2024-10-14 18:57:01]
  • 评测
  • 测评结果:WA
  • 用时:70ms
  • 内存:24788kb
  • [2024-10-14 18:57:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
struct Trajan_SCC
{
    static constexpr int N=200005;
    int n;
    Trajan_SCC(int _n=0):n(_n){}
    void resize(int _n)
    {
        n=_n;
        return;
    }
    vector<int>G[N];
    int dfn[N],low[N],Index;
    bool ins[N];
    stack<int>s;
    int bel[N],tot;
    vector<int>block[N];
    void dfs(int u)
    {
        dfn[u]=low[u]=++Index;
        ins[u]=true;
        s.push(u);
        for(int v:G[u])
        {
            if(!dfn[v])
            {
                dfs(v);
                low[u]=min(low[u],low[v]);
            }
            else if(ins[v]) low[u]=min(low[u],dfn[v]);
        }
        if(dfn[u]==low[u])
        {
            tot++;
            block[tot].clear();
            while(!s.empty()&&s.top()!=u)
            {
                int v=s.top();
                s.pop();
                ins[v]=false;
                bel[v]=tot;
                block[tot].push_back(v);
            }
            s.pop();
            ins[u]=false;
            bel[u]=tot;
            block[tot].push_back(u);
        }
        return;
    }
    void add_edge(int u,int v)
    {
        G[u].emplace_back(v);
        return;
    }
    void tarjan()
    {
        fill(dfn+1,dfn+n+1,0);
        fill(low+1,low+n+1,0);
        Index=0;
        fill(bel+1,bel+n+1,0);
        tot=0;
        for(int i=1;i<=n;i++)
            if(!dfn[i]) dfs(i);
        return;
    }
};
struct Two_Sat
{
    static constexpr int N=100005;
    int n,tot;
    array<int,2>id[N];
    Trajan_SCC scc;
    bool val[N];
    Two_Sat(int _n=0)
    {
        n=_n;
        tot=0;
        for(int i=1;i<=_n;i++)
            id[i][0]=++tot,id[i][1]=++tot;
        scc.resize(tot);
    }
    int new_node()
    {
        n++;
        id[n][0]=++tot,id[n][1]=++tot;
        scc.resize(tot);
        return n;
    }
    void add(int u,bool a,int v,bool b)
    {
        if(u==v)
        {
            scc.add_edge(id[u][a],id[v][b]);
            return;
        }
        scc.add_edge(id[u][a],id[u][b]);
        scc.add_edge(id[u][b^1],id[u][a^1]);
        return;
    }
    bool twosat()
    {
        scc.tarjan();
        for(int i=1;i<=n;i++)
            if(scc.bel[id[i][0]]==scc.bel[id[i][1]]) return false;
        for(int i=1;i<=n;i++)
            val[i]=scc.bel[id[i][0]]>scc.bel[id[i][1]];
        return true;
    }
};
int main()
{
    int n,m;
    cin>>n>>m;
    Two_Sat ts(n);
    for(int i=1;i<=m;i++)
    {
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        ts.add(a,b,c,d^1);
    }
    if(!ts.twosat())
    {
        cout<<"No";
        return 0;
    }
    cout<<"Yes\n";
    for(int i=1;i<=n;i++)
        cout<<ts.val[i]<<" ";
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 70ms
memory: 24788kb

input:

86354 86418
14615 0 14903 1
13605 0 4458 0
15604 0 77112 0
52311 1 64996 0
22711 1 74245 1
39042 1 57372 1
2994 1 84183 1
80574 0 58791 1
27780 1 9336 1
61809 0 7216 0
71113 0 42287 1
20073 0 72448 0
73840 0 77048 0
28955 0 4165 0
16322 1 14075 1
43512 0 58600 1
45219 0 53858 0
14919 0 22576 0
16594...

output:

No

result:

wrong answer You didn't find a solution but jury did.