結果
問題 | No.1266 7 Colors |
ユーザー | titia |
提出日時 | 2020-10-23 23:46:58 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,820 bytes |
コンパイル時間 | 318 ms |
コンパイル使用メモリ | 87,216 KB |
実行使用メモリ | 131,996 KB |
最終ジャッジ日時 | 2023-09-28 19:07:16 |
合計ジャッジ時間 | 38,149 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 77 ms
71,180 KB |
testcase_01 | AC | 79 ms
71,276 KB |
testcase_02 | AC | 82 ms
71,004 KB |
testcase_03 | AC | 2,792 ms
94,308 KB |
testcase_04 | AC | 1,714 ms
120,580 KB |
testcase_05 | AC | 2,304 ms
95,932 KB |
testcase_06 | AC | 1,768 ms
124,716 KB |
testcase_07 | AC | 1,780 ms
130,904 KB |
testcase_08 | AC | 1,699 ms
121,084 KB |
testcase_09 | AC | 1,788 ms
114,760 KB |
testcase_10 | AC | 1,779 ms
110,600 KB |
testcase_11 | AC | 2,026 ms
99,052 KB |
testcase_12 | AC | 1,843 ms
101,944 KB |
testcase_13 | AC | 1,805 ms
106,640 KB |
testcase_14 | AC | 2,319 ms
95,060 KB |
testcase_15 | AC | 1,756 ms
131,996 KB |
testcase_16 | AC | 1,808 ms
102,980 KB |
testcase_17 | AC | 1,764 ms
129,252 KB |
testcase_18 | AC | 1,129 ms
130,084 KB |
testcase_19 | AC | 1,131 ms
127,928 KB |
testcase_20 | AC | 1,148 ms
129,608 KB |
testcase_21 | TLE | - |
ソースコード
N,M,Q=map(int,input().split()) ANS=[[0]*7 for i in range(N)] S=[list(map(int,list(input().strip()))) for i in range(N)] E=[[] for i in range(N)] for i in range(M): x,y=map(int,input().split()) x-=1 y-=1 E[x].append(y) E[y].append(x) # UnionFind Group = [i for i in range(N*7)] # グループ分け Nodes = [1]*(N*7) # 各グループのノードの数 def find(x): while Group[x] != x: x=Group[x] return x def Union(x,y): if find(x) != find(y): if Nodes[find(x)] < Nodes[find(y)]: Nodes[find(y)] += Nodes[find(x)] Nodes[find(x)] = 0 Group[find(x)] = find(y) else: Nodes[find(x)] += Nodes[find(y)] Nodes[find(y)] = 0 Group[find(y)] = find(x) for i in range(N): for j in range(7): if S[i][j-1]==1 and S[i][j]==1: Union(i*7+(j-1)%7,i*7+j) for i in range(N): for to in E[i]: for j in range(7): if S[i][j]==1 and S[to][j]==1: Union(i*7+j,to*7+j) for i in range(Q): q,x,y=map(int,input().split()) if q==1: x-=1 y-=1 S[x][y]=1 Q=[x*7+y] while Q: town=Q.pop() x,y=divmod(town,7) town=find(town) if S[x][(y+1)%7]==1 and find(x*7+(y+1)%7)!=town: Union(x*7+y,x*7+(y+1)%7) Q.append(x*7+(y+1)%7) if S[x][(y-1)%7]==1 and find(x*7+(y-1)%7)!=town: Union(x*7+y,x*7+(y-1)%7) Q.append(x*7+(y-1)%7) for to in E[x]: if S[to][y]==1 and find(to*7+y)!=town: Union(x*7+y,to*7+y) Q.append(to*7+y) else: x-=1 print(Nodes[find(x*7)])