結果

問題 No.2536 同値性と充足可能性
ユーザー titiatitia
提出日時 2023-11-12 00:08:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,169 bytes
コンパイル時間 2,673 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 115,796 KB
最終ジャッジ日時 2023-11-12 00:08:23
合計ジャッジ時間 9,161 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 WA -
testcase_07 AC 56 ms
53,460 KB
testcase_08 WA -
testcase_09 AC 37 ms
53,460 KB
testcase_10 AC 38 ms
53,460 KB
testcase_11 AC 38 ms
53,460 KB
testcase_12 AC 39 ms
53,460 KB
testcase_13 AC 37 ms
53,460 KB
testcase_14 AC 38 ms
53,460 KB
testcase_15 AC 38 ms
53,460 KB
testcase_16 AC 37 ms
53,460 KB
testcase_17 AC 63 ms
73,292 KB
testcase_18 AC 51 ms
66,528 KB
testcase_19 AC 40 ms
58,944 KB
testcase_20 AC 63 ms
75,760 KB
testcase_21 AC 79 ms
76,488 KB
testcase_22 AC 81 ms
76,368 KB
testcase_23 AC 223 ms
81,648 KB
testcase_24 AC 184 ms
81,408 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 377 ms
102,676 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 340 ms
105,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,M=map(int,input().split())

E=[[] for i in range(N+1)]
E2=[[] for i in range(N+1)]

for i in range(M):
    S=input().split()
    x=int(S[0])
    y=int(S[-1])

    if len(S[1])==4:
        E[x].append(y)
        E[y].append(x)
    else:
        E2[x].append(y)
        E2[y].append(x)

# UnionFind

Group = [i for i in range(N+1)] # グループ分け
Nodes = [1]*(N+1) # 各グループのノードの数

def find(x):
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):
    if find(x) != find(y):
        if Nodes[find(x)] < Nodes[find(y)]:
            
            Nodes[find(y)] += Nodes[find(x)]
            Nodes[find(x)] = 0
            Group[find(x)] = find(y)
            
        else:
            Nodes[find(x)] += Nodes[find(y)]
            Nodes[find(y)] = 0
            Group[find(y)] = find(x)

for i in range(N+1):
    for to in E[i]:
        Union(i,to)

E3=[[] for i in range(N+1)]

for i in range(N+1):
    for to in E2[i]:
        if find(i)==find(to):
            print("No")
            exit()
        else:
            E3[find(i)].append(find(to))
            E3[find(to)].append(find(i))

ANS=[]
USE=[-1]*(N+1)

for i in range(N+1):
    if find(i)!=i:
        continue
    if USE[i]!=-1:
        continue

    Q=[i]
    USE[i]=0
    zero=Nodes[i]
    one=0
    Z=[i]
    O=[]

    while Q:
        x=Q.pop()
        for to in E3[i]:
            if USE[to]==-1:
                USE[to]=USE[i]^1

                if USE[to]==0:
                    zero+=Nodes[to]
                    Z.append(to)
                else:
                    one+=Nodes[to]
                    O.append(to)
                Q.append(to)
            else:
                if USE[to]==USE[i]^1:
                    pass
                else:
                    print("No")
                    exit()

    if zero>=one:
        for z in Z:
            ANS.append(z)
    else:
        for o in O:
            ANS.append(o)

SET=set(ANS)

LANS=[]
for i in range(1,N+1):
    if find(i) in SET:
        LANS.append(i)

print("Yes")
print(len(LANS))
print(*LANS)
                

    
    
        




        
0