結果

問題 No.2536 同値性と充足可能性
ユーザー ゼットゼット
提出日時 2023-11-11 07:57:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 453 ms / 2,000 ms
コード長 1,286 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 93,708 KB
最終ジャッジ日時 2023-11-11 07:57:31
合計ジャッジ時間 6,098 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 43 ms
53,460 KB
testcase_04 AC 40 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 36 ms
53,460 KB
testcase_07 AC 35 ms
53,460 KB
testcase_08 AC 36 ms
53,460 KB
testcase_09 AC 36 ms
53,460 KB
testcase_10 AC 36 ms
53,460 KB
testcase_11 AC 36 ms
53,460 KB
testcase_12 AC 36 ms
53,460 KB
testcase_13 AC 36 ms
53,460 KB
testcase_14 AC 36 ms
53,460 KB
testcase_15 AC 39 ms
53,460 KB
testcase_16 AC 36 ms
53,460 KB
testcase_17 AC 79 ms
76,608 KB
testcase_18 AC 79 ms
76,728 KB
testcase_19 AC 37 ms
53,460 KB
testcase_20 AC 37 ms
53,460 KB
testcase_21 AC 42 ms
59,232 KB
testcase_22 AC 46 ms
61,332 KB
testcase_23 AC 117 ms
77,348 KB
testcase_24 AC 109 ms
77,348 KB
testcase_25 AC 449 ms
92,776 KB
testcase_26 AC 453 ms
92,596 KB
testcase_27 AC 352 ms
92,036 KB
testcase_28 AC 446 ms
92,676 KB
testcase_29 AC 444 ms
93,708 KB
testcase_30 AC 318 ms
92,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class unif:
  def __init__(self,n):
    self.pare=[-1]*n
    self.size=[1]*n
    self.count=[0]*n
    for i in range(n):
      if i%2==0:
        self.count[i]=1
  def root(self,x):
    while self.pare[x]!=-1:
      x=self.pare[x]
    return x
  def unite(self,u,v):
    rootu=self.root(u)
    rootv=self.root(v)
    if rootu!=rootv:
      if self.size[rootu]>=self.size[rootv]:
        self.pare[rootv]=rootu
        self.size[rootu]+=self.size[rootv]
        self.count[rootu]+=self.count[rootv]
      else:
        self.pare[rootu]=rootv
        self.size[rootv]+=self.size[rootu]
        self.count[rootv]+=self.count[rootu]
  def same(self,s,t):
    return self.root(s)==self.root(t)
N,M=map(int,input().split())
Z=unif(2*N)
for i in range(M):
  a,s,b=input().split()
  a=int(a)
  b=int(b)
  a-=1
  b-=1
  if s=='<==>':
    if Z.same(2*a,2*b+1)==True:
      print('No')
      exit()
    Z.unite(2*a,2*b)
    Z.unite(2*a+1,2*b+1)
  else:
    if Z.same(2*a,2*b)==True:
      print('No')
      exit()
    Z.unite(2*a,2*b+1)
    Z.unite(2*b,2*a+1)
A=set()
print('Yes')
result=[]
NG=set()
for i in range(N):
  if Z.count[Z.root(2*i)]>=(Z.size[Z.root(2*i)]+1)//2:
    if Z.root(2*i) in NG:
      continue
    result.append(i+1)
    NG.add(Z.root(2*i+1))
print(len(result))
print(*result)
0