結果
問題 | No.2536 同値性と充足可能性 |
ユーザー |
![]() |
提出日時 | 2023-11-11 07:57:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 476 ms / 2,000 ms |
コード長 | 1,286 bytes |
コンパイル時間 | 243 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 95,988 KB |
最終ジャッジ日時 | 2024-09-26 02:37:27 |
合計ジャッジ時間 | 5,930 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
class unif:def __init__(self,n):self.pare=[-1]*nself.size=[1]*nself.count=[0]*nfor i in range(n):if i%2==0:self.count[i]=1def root(self,x):while self.pare[x]!=-1:x=self.pare[x]return xdef 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]=rootuself.size[rootu]+=self.size[rootv]self.count[rootu]+=self.count[rootv]else:self.pare[rootu]=rootvself.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-=1b-=1if 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:continueresult.append(i+1)NG.add(Z.root(2*i+1))print(len(result))print(*result)