結果

問題 No.3031 曲面の向き付け
ユーザー sasa8uyauya
提出日時 2025-02-21 23:32:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,328 ms / 2,000 ms
コード長 1,820 bytes
コンパイル時間 859 ms
コンパイル使用メモリ 81,976 KB
実行使用メモリ 204,572 KB
最終ジャッジ日時 2025-02-21 23:32:59
合計ジャッジ時間 13,702 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
e={}
v=[]
for i in range(n):
  a,b,c=map(int,input().split())
  for p in [(a,b),(b,c),(a,c)]:
    if p not in e:
      e[p]=[]
    e[p]+=[(a,b,c)]
    if len(e[p])==3:
      print("NO")
      exit()
  v+=[(a,b,c)]
u=set()
f={o:0 for o in v}
for o in v:
  if o not in u:
    q=[o]
    u.add(o)
    for s in q:
      a,b,c=s
      for p in [(a,b),(b,c),(a,c)]:
        if len(e[p])==2:
          t=e[p][e[p][0]==s]
          ta,tb,tc=t
          if t not in u:
            q+=[t]
            u.add(t)
            if f[s]:
              if p==(a,b):
                f[t]=int(a==ta and b==tc)
              if p==(b,c):
                f[t]=int(b==ta and c==tc)
              if p==(a,c):
                f[t]=1-int(a==ta and c==tc)
            else:
              if p==(a,b):
                f[t]=1-int(a==ta and b==tc)
              if p==(b,c):
                f[t]=1-int(b==ta and c==tc)
              if p==(a,c):
                f[t]=int(a==ta and c==tc)
          else:
            if f[s]:
              if p==(a,b):
                if f[t]!=int(a==ta and b==tc):
                  print("NO")
                  exit()
              if p==(b,c):
                if f[t]!=int(b==ta and c==tc):
                  print("NO")
                  exit()
              if p==(a,c):
                if f[t]!=1-int(a==ta and c==tc):
                  print("NO")
                  exit()
            else:
              if p==(a,b):
                if f[t]!=1-int(a==ta and b==tc):
                  print("NO")
                  exit()
              if p==(b,c):
                if f[t]!=1-int(b==ta and c==tc):
                  print("NO")
                  exit()
              if p==(a,c):
                if f[t]!=int(a==ta and c==tc):
                  print("NO")
                  exit()
print("YES")
0