提出 #17348313
ソースコード 拡げる
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
uf_t = numba.types.UniTuple(i8[:], 2)
@njit((uf_t, i8), cache=True)
def find_root(uf, x):
root = uf[0]
while root[x] != x:
root[x] = root[root[x]]
x = root[x]
return x
@njit((uf_t, i8, i8), cache=True)
def merge(uf, x, y):
root, size = uf
x, y = find_root(uf, x), find_root(uf, y)
if x == y:
return False
if size[x] < size[y]:
x, y = y, x
size[x] += size[y]
root[y] = root[x]
return True
@njit((i8, i8, i8[:]), cache=True)
def solve(N, M, AB):
last_M = N * (N - 1) // 2
add = last_M - M
if N % 2 == 1:
# 運命は決まっている
return add % 2 == 1
# 以下、偶数頂点
A, B = AB[::2], AB[1::2]
root = np.arange(N + 1, dtype=np.int64)
size = np.ones_like(root)
uf = (root, size)
for i in range(len(A)):
merge(uf, A[i], B[i])
r0, r1 = find_root(uf, 1), find_root(uf, N)
s0, s1 = size[r0], size[r1]
# 先手の理想形は?
if add % 2 == 0:
# 先手は (od, od) を目指すことになる
if s0 % 2 == 0 and s1 % 2 == 0:
return False
return True
else:
# 先手は (ev, ev) を目指すことになる
if s0 % 2 == 1 and s1 % 2 == 1:
return False
return True
@njit((i8[:], ), cache=True)
def main(nums):
T, nums = nums[0], nums[1:]
for _ in range(T):
N, M = nums[:2]
nums = nums[2:]
AB = nums[:M + M]
nums = nums[M + M:]
print('First' if solve(N, M, AB) else 'Second')
nums = np.array(read().split(), np.int64)
main(nums)
提出情報
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
700 / 700 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
sample_01.txt |
| All |
random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| random_01.txt |
AC |
523 ms |
106500 KiB |
| random_02.txt |
AC |
515 ms |
113480 KiB |
| random_03.txt |
AC |
530 ms |
119936 KiB |
| random_04.txt |
AC |
534 ms |
120264 KiB |
| random_05.txt |
AC |
538 ms |
123292 KiB |
| random_06.txt |
AC |
538 ms |
122640 KiB |
| random_07.txt |
AC |
528 ms |
119948 KiB |
| random_08.txt |
AC |
541 ms |
124608 KiB |
| random_09.txt |
AC |
549 ms |
126284 KiB |
| random_10.txt |
AC |
548 ms |
126664 KiB |
| random_11.txt |
AC |
531 ms |
119148 KiB |
| random_12.txt |
AC |
533 ms |
119116 KiB |
| random_13.txt |
AC |
536 ms |
119080 KiB |
| random_14.txt |
AC |
534 ms |
119056 KiB |
| random_15.txt |
AC |
535 ms |
118672 KiB |
| random_16.txt |
AC |
531 ms |
119108 KiB |
| random_17.txt |
AC |
528 ms |
119656 KiB |
| random_18.txt |
AC |
532 ms |
118668 KiB |
| random_19.txt |
AC |
482 ms |
107416 KiB |
| random_20.txt |
AC |
526 ms |
118828 KiB |
| sample_01.txt |
AC |
481 ms |
106144 KiB |