結果
問題 | No.1266 7 Colors |
ユーザー | tpyneriver |
提出日時 | 2020-10-23 22:39:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 750 ms / 3,000 ms |
コード長 | 1,733 bytes |
コンパイル時間 | 525 ms |
コンパイル使用メモリ | 87,256 KB |
実行使用メモリ | 101,852 KB |
最終ジャッジ日時 | 2023-09-28 16:49:35 |
合計ジャッジ時間 | 14,472 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 77 ms
71,416 KB |
testcase_01 | AC | 79 ms
71,420 KB |
testcase_02 | AC | 76 ms
71,448 KB |
testcase_03 | AC | 565 ms
90,936 KB |
testcase_04 | AC | 699 ms
97,364 KB |
testcase_05 | AC | 563 ms
90,980 KB |
testcase_06 | AC | 697 ms
97,980 KB |
testcase_07 | AC | 742 ms
99,892 KB |
testcase_08 | AC | 702 ms
97,280 KB |
testcase_09 | AC | 661 ms
94,944 KB |
testcase_10 | AC | 639 ms
93,548 KB |
testcase_11 | AC | 571 ms
91,440 KB |
testcase_12 | AC | 595 ms
92,360 KB |
testcase_13 | AC | 619 ms
93,472 KB |
testcase_14 | AC | 567 ms
91,328 KB |
testcase_15 | AC | 732 ms
100,036 KB |
testcase_16 | AC | 605 ms
93,096 KB |
testcase_17 | AC | 750 ms
99,608 KB |
testcase_18 | AC | 454 ms
101,852 KB |
testcase_19 | AC | 563 ms
95,816 KB |
testcase_20 | AC | 546 ms
95,904 KB |
testcase_21 | AC | 220 ms
86,312 KB |
ソースコード
import sys readline = sys.stdin.readline class UF(): def __init__(self, num): self.par = [-1]*num def find(self, x): if self.par[x] < 0: return x else: stack = [] while self.par[x] >= 0: stack.append(x) x = self.par[x] for xi in stack: self.par[xi] = x return x def union(self, x, y): rx = self.find(x) ry = self.find(y) if rx != ry: if self.par[rx] > self.par[ry]: rx, ry = ry, rx self.par[rx] += self.par[ry] self.par[ry] = rx return True return False N, M, Q = map(int, readline().split()) color = [int(readline().strip()[::-1], 2) for _ in range(N)] C = 7 Edge = [[] for _ in range(N)] T = UF(N*C) for _ in range(M): u, v = map(int, readline().split()) u -= 1 v -= 1 Edge[u].append(v) Edge[v].append(u) for i in range(C): if (color[u]>>i) & 1 and (color[v]>>i) & 1: T.union(u*C+i, v*C+i) for i in range(N): for c in range(C): cf = (c+1)%C if (color[i]>>c) & 1 and (color[i]>>cf) & 1: T.union(i*C+c, i*C+cf) Ans = [] for _ in range(Q): t, x, y = map(int, readline().split()) x -= 1 y -= 1 if t == 1: color[x] |= 1<<y for vf in Edge[x]: if (color[vf]>>y)&1: T.union(x*C+y, vf*C+y) cm = ((y-1)%C) if (color[x]>>cm)&1: T.union(x*C+cm, x*C+y) cp = ((y+1)%C) if (color[x]>>cp)&1: T.union(x*C+cp, x*C+y) else: Ans.append(-T.par[T.find(x*C)]) print('\n'.join(map(str, Ans)))