結果

問題 No.408 五輪ピック
コンテスト
ユーザー YuuuT
提出日時 2026-11-23 16:11:38
言語 Python3
(3.15.2 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
TLE  
実行時間 -
コード長 1,488 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 86 ms
コンパイル使用メモリ 14,848 KB
実行使用メモリ 14,208 KB
最終ジャッジ日時 2026-11-23 16:12:39
合計ジャッジ時間 53,750 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23 TLE * 4 -- * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# library: https://github.com/yu-0811/competitive-programming-library
import sys,math;sys.setrecursionlimit(10**9)
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')
from collections import defaultdict,deque
from itertools import combinations,permutations,accumulate,product
from bisect import bisect_left,bisect_right
from heapq import heappop,heappush,heapify
#from more_itertools import distinct_permutations,distinct_combinations
def input():return sys.stdin.readline().rstrip()
def ii(): return int(input())
def ms(): return map(int, input().split())
def li(): return list(map(int,input().split()))
inf = pow(10,18)
mod = 998244353
#//////////////////////////
N,M = ms()
from array import array
G = [array('i') for i in range(N)]
for i in range(M):
    a,b = ms()
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

def solve(C,K):
    # https://info.atcoder.jp/entry/algorithm_lectures/color_coding
    # 問題2の解法
    dp = [False]*N
    dp[0] = True

    for i in range(1,K):
        nx = [False]*N
        for v in range(N):
            if C[v] != i: continue
            for u in G[v]:
                if dp[u]:
                    nx[v] = True
                    break
        dp = nx

    for u in G[0]:
        if dp[u]:
            return True
    
    return False

from random import randint
C = [0]*N
for _ in range(500):
    for i in range(1,N):
        C[i] = randint(1,4)
    if solve(C,5):
        print("YES")
        exit()

print("NO")
0