結果

問題 No.483 マッチ並べ
ユーザー 0w10w1
提出日時 2017-04-15 17:57:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 909 bytes
コンパイル時間 965 ms
コンパイル使用メモリ 86,568 KB
実行使用メモリ 75,164 KB
最終ジャッジ日時 2023-09-25 22:17:17
合計ジャッジ時間 7,579 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,128 KB
testcase_01 AC 72 ms
71,072 KB
testcase_02 AC 71 ms
71,344 KB
testcase_03 AC 72 ms
71,348 KB
testcase_04 AC 72 ms
71,268 KB
testcase_05 AC 74 ms
71,004 KB
testcase_06 AC 74 ms
71,212 KB
testcase_07 AC 73 ms
71,368 KB
testcase_08 AC 71 ms
71,188 KB
testcase_09 AC 72 ms
70,928 KB
testcase_10 AC 72 ms
71,212 KB
testcase_11 AC 73 ms
70,848 KB
testcase_12 AC 73 ms
71,160 KB
testcase_13 AC 72 ms
71,000 KB
testcase_14 AC 72 ms
71,196 KB
testcase_15 AC 72 ms
71,012 KB
testcase_16 AC 71 ms
71,168 KB
testcase_17 AC 74 ms
71,372 KB
testcase_18 AC 71 ms
71,076 KB
testcase_19 AC 71 ms
71,184 KB
testcase_20 AC 71 ms
70,936 KB
testcase_21 AC 70 ms
71,124 KB
testcase_22 AC 70 ms
71,016 KB
testcase_23 AC 72 ms
71,188 KB
testcase_24 AC 72 ms
71,156 KB
testcase_25 AC 72 ms
70,924 KB
testcase_26 AC 73 ms
74,900 KB
testcase_27 AC 75 ms
74,852 KB
testcase_28 AC 76 ms
74,856 KB
testcase_29 AC 72 ms
71,156 KB
testcase_30 AC 74 ms
74,916 KB
testcase_31 AC 74 ms
74,876 KB
testcase_32 AC 75 ms
75,164 KB
testcase_33 AC 70 ms
71,168 KB
testcase_34 AC 70 ms
71,128 KB
testcase_35 AC 71 ms
71,172 KB
testcase_36 AC 70 ms
71,144 KB
testcase_37 AC 74 ms
74,964 KB
testcase_38 AC 75 ms
74,908 KB
testcase_39 AC 75 ms
74,956 KB
testcase_40 AC 72 ms
71,332 KB
testcase_41 AC 75 ms
74,900 KB
testcase_42 AC 76 ms
74,996 KB
testcase_43 AC 73 ms
74,920 KB
testcase_44 AC 70 ms
71,148 KB
testcase_45 AC 71 ms
70,996 KB
testcase_46 AC 71 ms
70,920 KB
testcase_47 AC 75 ms
74,908 KB
testcase_48 AC 74 ms
75,144 KB
testcase_49 AC 74 ms
74,956 KB
testcase_50 AC 76 ms
75,140 KB
testcase_51 AC 74 ms
74,920 KB
testcase_52 AC 78 ms
74,912 KB
testcase_53 AC 75 ms
71,188 KB
testcase_54 AC 69 ms
71,072 KB
testcase_55 AC 70 ms
71,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int( input() )
R0 = []
C0 = []
R1 = []
C1 = []
bag = set()
for i in range( N ):
  r0, c0, r1, c1 = map( int, input().split() )
  R0.append( r0 )
  C0.append( c0 )
  bag.add( ( r0, c0 ) )
  R1.append( r1 )
  C1.append( c1 )
  bag.add( ( r1, c1 ) )

mp = dict()
_ = 0
for key in bag:
  mp[ key ] = _
  _ += 1
G = [ [] for i in range( N ) ]
for i in range( N ):
  G[ i ].append( mp[ ( R0[ i ], C0[ i ] ) ] )
  G[ i ].append( mp[ ( R1[ i ], C1[ i ] ) ] )

def dfs( u, bf, vis = None ):
  if vis == None:
    vis = [ False for i in range( len( mp ) ) ]
  for i in range( len( G[ u ] ) ):
    if vis[ G[ u ][ i ] ]: continue
    vis[ G[ u ][ i ] ] = True
    if bf[ G[ u ][ i ] ] == -1 or dfs( bf[ G[ u ][ i ] ], bf, vis ):
      bf[ G[ u ][ i ] ] = u
      return True
  return False

bf = [ -1 for i in range( len( mp ) ) ]
for i in range( N ):
  if not dfs( i, bf ):
    exit( print( "NO" ) )
print( "YES" )
0