結果
問題 | No.2948 move move rotti |
ユーザー | hato336 |
提出日時 | 2024-10-25 21:40:52 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,386 ms / 4,000 ms |
コード長 | 2,382 bytes |
コンパイル時間 | 380 ms |
コンパイル使用メモリ | 82,360 KB |
実行使用メモリ | 180,772 KB |
最終ジャッジ日時 | 2024-10-25 21:41:10 |
合計ジャッジ時間 | 17,265 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 139 ms
89,200 KB |
testcase_01 | AC | 138 ms
89,428 KB |
testcase_02 | AC | 136 ms
89,256 KB |
testcase_03 | AC | 558 ms
118,836 KB |
testcase_04 | AC | 520 ms
178,928 KB |
testcase_05 | AC | 139 ms
89,200 KB |
testcase_06 | AC | 154 ms
90,212 KB |
testcase_07 | AC | 644 ms
179,464 KB |
testcase_08 | AC | 1,386 ms
180,772 KB |
testcase_09 | AC | 776 ms
136,460 KB |
testcase_10 | AC | 143 ms
88,944 KB |
testcase_11 | AC | 142 ms
89,504 KB |
testcase_12 | AC | 192 ms
92,260 KB |
testcase_13 | AC | 397 ms
127,088 KB |
testcase_14 | AC | 349 ms
124,888 KB |
testcase_15 | AC | 316 ms
101,880 KB |
testcase_16 | AC | 930 ms
150,028 KB |
testcase_17 | AC | 534 ms
118,920 KB |
testcase_18 | AC | 825 ms
149,360 KB |
testcase_19 | AC | 715 ms
157,980 KB |
testcase_20 | AC | 995 ms
180,740 KB |
testcase_21 | AC | 1,360 ms
180,564 KB |
testcase_22 | AC | 790 ms
180,696 KB |
testcase_23 | AC | 1,171 ms
180,176 KB |
testcase_24 | AC | 761 ms
180,280 KB |
testcase_25 | AC | 929 ms
180,752 KB |
testcase_26 | AC | 168 ms
90,200 KB |
testcase_27 | AC | 139 ms
89,076 KB |
testcase_28 | AC | 176 ms
90,292 KB |
testcase_29 | AC | 136 ms
89,060 KB |
testcase_30 | AC | 168 ms
90,316 KB |
ソースコード
import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random #sys.setrecursionlimit(10**9) #sys.set_int_max_str_digits(0) #input = sys.stdin.readline #alist = list(map(int,input().split())) class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = collections.defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return ''.join(f'{r}: {m}' for r, m in self.all_group_members().items()) #alist = [] #s = input() n,m,k = map(int,input().split()) x = list(map(lambda x:int(x)-1,input().split())) x = list(set(x)) edge = [[] for i in range(n)] for i in range(m): u,v = map(int,input().split()) u-=1 v-=1 edge[u].append(v) edge[v].append(u) ans = [[set() for i in range(n+1)] for j in range(n+1)] for y in x: dist = [[0 for i in range(n)] for j in range(1<<n)] dist[1<<y][y] = 1 for s in range(1<<n): for i in range(n): if(s >> i) & 1 == 0: continue for j in edge[i]: if(s >> j) & 1 == 1: continue dist[s | (1 << j)][j] |= dist[s][i] if dist[s][i] == 1: ans[i][s.bit_count()].add(y) for i in range(n+1): for j in range(n+1): if len(ans[i][j]) == len(x) : exit(print('Yes')) print('No')