結果
問題 | No.1266 7 Colors |
ユーザー | stnkien |
提出日時 | 2020-10-23 23:14:31 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,098 ms / 3,000 ms |
コード長 | 1,644 bytes |
コンパイル時間 | 361 ms |
コンパイル使用メモリ | 86,772 KB |
実行使用メモリ | 127,056 KB |
最終ジャッジ日時 | 2023-09-28 18:25:48 |
合計ジャッジ時間 | 17,357 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 75 ms
71,200 KB |
testcase_01 | AC | 74 ms
71,168 KB |
testcase_02 | AC | 74 ms
71,192 KB |
testcase_03 | AC | 482 ms
102,036 KB |
testcase_04 | AC | 939 ms
118,016 KB |
testcase_05 | AC | 576 ms
103,580 KB |
testcase_06 | AC | 964 ms
120,164 KB |
testcase_07 | AC | 1,039 ms
124,592 KB |
testcase_08 | AC | 985 ms
118,840 KB |
testcase_09 | AC | 875 ms
113,908 KB |
testcase_10 | AC | 826 ms
112,544 KB |
testcase_11 | AC | 740 ms
107,192 KB |
testcase_12 | AC | 756 ms
107,736 KB |
testcase_13 | AC | 869 ms
109,340 KB |
testcase_14 | AC | 673 ms
103,988 KB |
testcase_15 | AC | 1,098 ms
123,752 KB |
testcase_16 | AC | 763 ms
107,148 KB |
testcase_17 | AC | 957 ms
122,260 KB |
testcase_18 | AC | 323 ms
127,056 KB |
testcase_19 | AC | 334 ms
122,172 KB |
testcase_20 | AC | 338 ms
121,864 KB |
testcase_21 | AC | 193 ms
96,512 KB |
ソースコード
import sys read=sys.stdin.read readlines=sys.stdin.readlines input=sys.stdin.readline N, M, Q = map(int, input().split()) S = [list(map(int, input().rstrip())) for _ in [0]*N] class UnionFind: def __init__(self, n=0): self.d = [-1]*n self.u = n def root(self, x): if self.d[x] < 0: return x self.d[x] = self.root(self.d[x]) return self.d[x] def unite(self, x, y): x, y = self.root(x), self.root(y) if x == y: return False if x > y: x, y = y, x self.d[x] += self.d[y] self.d[y] = x self.u -= 1 return True def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.d[self.root(x)] def num_union(self): return self.u uf = UnionFind(N*7) for i in range(N): for c in range(7): if S[i][c] and S[i][c-1]: uf.unite(i*7+c, i*7+(c-1)%7) G = [[] for _ in range(N)] for _ in [0]*M: a, b = map(int, input().split()) a -= 1; b -= 1 G[a].append(b) G[b].append(a) for c in range(7): if S[a][c] == 0 or S[b][c] == 0: continue uf.unite(a*7+c, b*7+c) ans = [] for line in readlines(): k, x, c = map(int, line.split()) x -= 1; c -= 1 if k == 1: S[x][c] = 1 for v in G[x]: if S[v][c] == 0: continue uf.unite(x*7+c, v*7+c) if S[x][(c+1)%7]: uf.unite(x*7+c, x*7+(c+1)%7) if S[x][c-1]: uf.unite(x*7+c, x*7+(c-1)%7) else: ans.append(uf.size(x*7)) print('\n'.join(map(str, ans)))