結果
問題 | No.1266 7 Colors |
ユーザー | roaris |
提出日時 | 2020-11-14 14:11:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,016 ms / 3,000 ms |
コード長 | 1,911 bytes |
コンパイル時間 | 1,227 ms |
コンパイル使用メモリ | 86,740 KB |
実行使用メモリ | 141,916 KB |
最終ジャッジ日時 | 2023-09-30 04:58:17 |
合計ジャッジ時間 | 19,019 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 75 ms
70,996 KB |
testcase_01 | AC | 74 ms
70,984 KB |
testcase_02 | AC | 76 ms
71,068 KB |
testcase_03 | AC | 710 ms
91,844 KB |
testcase_04 | AC | 1,016 ms
121,088 KB |
testcase_05 | AC | 750 ms
94,280 KB |
testcase_06 | AC | 971 ms
127,464 KB |
testcase_07 | AC | 947 ms
132,628 KB |
testcase_08 | AC | 920 ms
122,376 KB |
testcase_09 | AC | 884 ms
111,464 KB |
testcase_10 | AC | 877 ms
108,996 KB |
testcase_11 | AC | 788 ms
98,432 KB |
testcase_12 | AC | 878 ms
102,512 KB |
testcase_13 | AC | 824 ms
104,188 KB |
testcase_14 | AC | 786 ms
95,708 KB |
testcase_15 | AC | 982 ms
134,256 KB |
testcase_16 | AC | 836 ms
102,136 KB |
testcase_17 | AC | 957 ms
131,268 KB |
testcase_18 | AC | 628 ms
141,916 KB |
testcase_19 | AC | 587 ms
135,872 KB |
testcase_20 | AC | 567 ms
135,060 KB |
testcase_21 | AC | 247 ms
81,744 KB |
ソースコード
import sys input = sys.stdin.readline class Unionfind: def __init__(self, n): self.par = [-1]*n self.rank = [1]*n def root(self, x): r = x while not self.par[r]<0: r = self.par[r] t = x while t!=r: tmp = t t = self.par[t] self.par[tmp] = r return r def unite(self, x, y): rx = self.root(x) ry = self.root(y) if rx==ry: return if self.rank[rx]<=self.rank[ry]: self.par[ry] += self.par[rx] self.par[rx] = ry if self.rank[rx]==self.rank[ry]: self.rank[ry] += 1 else: self.par[rx] += self.par[ry] self.par[ry] = rx def is_same(self, x, y): return self.root(x)==self.root(y) def count(self, x): return -self.par[self.root(x)] N, M, Q = map(int, input().split()) s = [list(input()[:-1]) for _ in range(N)] uf = Unionfind(7*N) for i in range(N): for j in range(7): if s[i][j]=='1' and s[i][(j+1)%7]=='1': uf.unite(7*i+j, 7*i+(j+1)%7) G = [[] for _ in range(N)] for _ in range(M): u, v = map(int, input().split()) G[u-1].append(v-1) G[v-1].append(u-1) for i in range(7): if s[u-1][i]=='1' and s[v-1][i]=='1': uf.unite(7*(u-1)+i, 7*(v-1)+i) for _ in range(Q): com = tuple(map(int, input().split())) if com[0]==1: x, y = com[1]-1, com[2]-1 s[x][y] = '1' if s[x][(y-1)%7]=='1': uf.unite(7*x+(y-1)%7, 7*x+y) if s[x][(y+1)%7]=='1': uf.unite(7*x+(y+1)%7, 7*x+y) for nx in G[x]: if s[nx][y]=='1': uf.unite(7*x+y, 7*nx+y) else: print(uf.count(7*(com[1]-1)))