結果

問題 No.2536 同値性と充足可能性
ユーザー ニックネームニックネーム
提出日時 2023-11-10 22:22:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 819 bytes
コンパイル時間 128 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 17,664 KB
最終ジャッジ日時 2023-11-10 22:22:19
合計ジャッジ時間 7,857 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,112 KB
testcase_01 AC 30 ms
10,112 KB
testcase_02 AC 29 ms
10,112 KB
testcase_03 AC 28 ms
10,112 KB
testcase_04 AC 28 ms
10,112 KB
testcase_05 AC 28 ms
10,112 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 29 ms
10,112 KB
testcase_10 AC 29 ms
10,112 KB
testcase_11 AC 29 ms
10,112 KB
testcase_12 AC 28 ms
10,112 KB
testcase_13 AC 29 ms
10,112 KB
testcase_14 AC 29 ms
10,112 KB
testcase_15 AC 29 ms
10,112 KB
testcase_16 AC 28 ms
10,112 KB
testcase_17 AC 33 ms
10,112 KB
testcase_18 AC 32 ms
10,112 KB
testcase_19 AC 28 ms
10,112 KB
testcase_20 AC 66 ms
10,240 KB
testcase_21 AC 67 ms
10,240 KB
testcase_22 AC 67 ms
10,240 KB
testcase_23 AC 418 ms
10,496 KB
testcase_24 AC 446 ms
10,496 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 617 ms
17,152 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 620 ms
17,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UF:
    def __init__(self,n):
        self.p = [-1]*n
    def f(self,x):
        if self.p[x]<0: return x
        else: self.p[x] = self.f(self.p[x]); return self.p[x]
    def u(self,x,y):
        x = self.f(x); y = self.f(y)
        if x==y: return
        if -self.p[x]<-self.p[y]: x,y = y,x
        self.p[x] += self.p[y]; self.p[y] = x
    def s(self,x,y): return self.f(x) == self.f(y)
n,m = map(int,input().split())
uf = UF(2*n)
for _ in range(m):
    i,e,j = input().split()
    i,j = int(i)-1,int(j)-1
    if e=="<==>": uf.u(i,j); uf.u(i+n,j+n)
    else: uf.u(i,j+n); uf.u(i+n,j)
for i in range(n):
    if uf.s(i,i+n): exit(print("No"))
a = [i+1 for i in range(n) if uf.f(i)==uf.f(0)]
b = [i+1 for i in range(n) if uf.f(i)!=uf.f(0)]
print("Yes"); print(max(len(a),len(b)))
print(*a if len(b)<=n//2 else b)
0