結果
問題 | No.1266 7 Colors |
ユーザー | tyawanmusi |
提出日時 | 2020-10-23 22:15:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,208 ms / 3,000 ms |
コード長 | 1,730 bytes |
コンパイル時間 | 305 ms |
コンパイル使用メモリ | 86,956 KB |
実行使用メモリ | 116,748 KB |
最終ジャッジ日時 | 2023-09-28 16:06:54 |
合計ジャッジ時間 | 17,374 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 77 ms
71,560 KB |
testcase_01 | AC | 76 ms
71,484 KB |
testcase_02 | AC | 75 ms
71,480 KB |
testcase_03 | AC | 545 ms
88,356 KB |
testcase_04 | AC | 1,052 ms
108,156 KB |
testcase_05 | AC | 643 ms
90,628 KB |
testcase_06 | AC | 1,069 ms
112,648 KB |
testcase_07 | AC | 1,137 ms
116,476 KB |
testcase_08 | AC | 1,206 ms
113,876 KB |
testcase_09 | AC | 947 ms
103,596 KB |
testcase_10 | AC | 890 ms
99,156 KB |
testcase_11 | AC | 666 ms
92,668 KB |
testcase_12 | AC | 767 ms
94,876 KB |
testcase_13 | AC | 862 ms
97,240 KB |
testcase_14 | AC | 618 ms
90,700 KB |
testcase_15 | AC | 1,208 ms
116,748 KB |
testcase_16 | AC | 819 ms
96,400 KB |
testcase_17 | AC | 1,186 ms
115,796 KB |
testcase_18 | AC | 332 ms
115,828 KB |
testcase_19 | AC | 331 ms
113,560 KB |
testcase_20 | AC | 331 ms
112,936 KB |
testcase_21 | AC | 242 ms
81,396 KB |
ソースコード
import sys input = lambda:sys.stdin.readline().rstrip() class UnionFind: def __init__(self, n): self.n = [-1]*n self.r = [0]*n self.siz = n def find_root(self, x): if self.n[x] < 0: return x else: self.n[x] = self.find_root(self.n[x]) return self.n[x] def unite(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return elif self.r[x] > self.r[y]: self.n[x] += self.n[y] self.n[y] = x else: self.n[y] += self.n[x] self.n[x] = y if self.r[x] == self.r[y]: self.r[y] += 1 self.siz -= 1 def root_same(self, x, y): return self.find_root(x) == self.find_root(y) def count(self, x): return -self.n[self.find_root(x)] def size(self): return self.siz n,m,q=map(int,input().split()) color=[[0]*7 for _ in range(n)] for i in range(n): s=input() for j in range(7): if s[j]=="1": color[i][j]=1 uf=UnionFind(n*7) edge=[[]for _ in range(n)] for _ in range(m): u,v=map(int,input().split()) u-=1 v-=1 edge[u].append(v) edge[v].append(u) f=lambda x,c: x*7+c for i in range(n): for j in range(7): if color[i][j]==color[i][(j+1)%7]==1: uf.unite(f(i,j),f(i,(j+1)%7)) for j in edge[i]: for k in range(7): if color[i][k]==color[j][k]==1: uf.unite(f(i,k),f(j,k)) for _ in range(q): qq=list(map(int,input().split())) if qq[0]==1: x,y=qq[1:] x-=1 y-=1 color[x][y]=1 if color[x][(y-1)%7]==1: uf.unite(f(x,y),f(x,(y-1)%7)) if color[x][(y+1)%7]==1: uf.unite(f(x,y),f(x,(y+1)%7)) for i in edge[x]: if color[i][y]==1: uf.unite(f(x,y),f(i,y)) else: x=qq[1]-1 print(uf.count(f(x,0)))