結果

問題 No.274 The Wall
ユーザー behoma8behoma8
提出日時 2023-03-07 15:45:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,713 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 81,604 KB
実行使用メモリ 309,960 KB
最終ジャッジ日時 2023-10-18 05:30:53
合計ジャッジ時間 6,363 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import sys
from collections import defaultdict
from collections import deque

INF = sys.maxsize
sys.setrecursionlimit( 10 ** 8 )

def alg_graph_scc( gs, rgs, n ):
    """
        gs: 隣接リスト
        rgs: 逆向き隣接リスト
    """
    order = []
    used = [0]*n
    group = [None]*n
    def dfs(s):
        used[s] = 1
        for t in gs[s]:
            if not used[t]:
                dfs(t)
        order.append(s)
    def rdfs(s, col):
        group[s] = col
        used[s] = 1
        for t in rgs[s]:
            if not used[t]:
                rdfs(t, col)
    for i in range(n):
        if not used[i]:
            dfs(i)
    used = [0]*n
    label = 0
    for s in reversed(order):
        if not used[s]:
            rdfs(s, label)
            label += 1
    return label, group


N, M = [ int(i) for i in input().split() ]
LR = [ [ int(i) for i in input().split() ] for _ in range( N ) ]
def solve():

    LRT = []
    for l, r in LR:
        LRT.append( ( M - 1 - l, M - 1 - r ) )

    gs = [[] for _ in range(2*N)]
    for i in range(N):
        l0, r0 = LR[i]
        for j in range(N):
            if i != j:
                l1, r1 = LRT[j]
                if not ( r0 < l1 or r1 < l0 ): # conflict
                    gs[i].append( j )
                    gs[N+j].append( N+i )
                l1, r1 = LR[j]
                if not( r0 < l1 or r1 < l0 ): # conflict
                    gs[i].append( N+j )
                    gs[N+j].append( i )
#    print( gs )
    label, group = alg_graph_scc( gs, gs, 2*N )
#    print( label, group )
    for i in range(N):
        if group[i] == group[i+N]:
            print( 'No' )
            return
    print( 'Yes' )

solve()
0