結果

問題 No.2536 同値性と充足可能性
ユーザー hato336hato336
提出日時 2023-11-10 22:00:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,561 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 162,936 KB
最終ジャッジ日時 2023-11-10 22:00:13
合計ジャッジ時間 10,449 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
84,664 KB
testcase_01 AC 132 ms
84,664 KB
testcase_02 AC 133 ms
84,664 KB
testcase_03 AC 136 ms
84,664 KB
testcase_04 AC 137 ms
84,664 KB
testcase_05 AC 137 ms
84,664 KB
testcase_06 AC 134 ms
84,664 KB
testcase_07 AC 132 ms
84,664 KB
testcase_08 AC 133 ms
84,664 KB
testcase_09 WA -
testcase_10 AC 135 ms
84,664 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 147 ms
88,248 KB
testcase_20 AC 204 ms
96,184 KB
testcase_21 AC 204 ms
95,544 KB
testcase_22 AC 228 ms
95,672 KB
testcase_23 AC 419 ms
162,276 KB
testcase_24 AC 399 ms
162,936 KB
testcase_25 AC 523 ms
161,556 KB
testcase_26 AC 498 ms
157,800 KB
testcase_27 AC 500 ms
162,544 KB
testcase_28 AC 478 ms
161,644 KB
testcase_29 AC 504 ms
158,732 KB
testcase_30 AC 431 ms
159,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
def two_sat(n,clause):
    answer=[0]*n
    edges=[]
    N=2*n
    for s in clause:
        i,f,j,g=s
        edges.append((2*i+(0 if f else 1),2*j+(1 if g else 0)))
        edges.append((2*j+(0 if g else 1),2*i+(1 if f else 0)))
    M=len(edges)
    start=[0]*(N+1)
    elist=[0]*M
    for e in edges:
        start[e[0]+1]+=1
    for i in range(1,N+1):
        start[i]+=start[i-1]
    counter=start[:]
    for e in edges:
        elist[counter[e[0]]]=e[1]
        counter[e[0]]+=1
    visited=[]
    low=[0]*N
    Ord=[-1]*N
    ids=[0]*N
    NG=[0,0]
    def dfs(v):
        stack=[(v,-1,0),(v,-1,1)]
        while stack:
            v,bef,t=stack.pop()
            if t:
                if bef!=-1 and Ord[v]!=-1:
                    low[bef]=min(low[bef],Ord[v])
                    stack.pop()
                    continue
                low[v]=NG[0]
                Ord[v]=NG[0]
                NG[0]+=1
                visited.append(v)
                for i in range(start[v],start[v+1]):
                    to=elist[i]
                    if Ord[to]==-1:
                        stack.append((to,v,0))
                        stack.append((to,v,1))
                    else:
                        low[v]=min(low[v],Ord[to])
            else:
                if low[v]==Ord[v]:
                    while(True):
                        u=visited.pop()
                        Ord[u]=N
                        ids[u]=NG[1]
                        if u==v:
                            break
                    NG[1]+=1
                low[bef]=min(low[bef],low[v])
    for i in range(N):
        if Ord[i]==-1:
            dfs(i)
    for i in range(N):
        ids[i]=NG[1]-1-ids[i]
    for i in range(n):
        if ids[2*i]==ids[2*i+1]:
            return None
        answer[i]=(ids[2*i]<ids[2*i+1])
    return answer
input = sys.stdin.readline

n,m = map(int,input().split())
clause = []
for _ in range(m):
    i,e,j = input().split()
    i = int(i)-1
    j = int(j)-1
    if e[2] == '/':
        clause.append((i,True,j,True))
        clause.append((i,False,j,False))
    else:
        clause.append((i,True,j,False))
        clause.append((i,False,j,True))
ans = two_sat(n,clause)
if ans == None:
    print('No')
else:
    print('Yes')
    a = []
    cnt = 0
    for i in range(n):
        if ans[i] == False:
            a.append(i+1)
            cnt += 1
    print(cnt)
    print(*a)
0