結果
問題 | No.2072 Anatomy |
ユーザー | ytft |
提出日時 | 2022-09-22 20:46:08 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 687 ms / 2,000 ms |
コード長 | 933 bytes |
コンパイル時間 | 253 ms |
コンパイル使用メモリ | 87,108 KB |
実行使用メモリ | 135,208 KB |
最終ジャッジ日時 | 2023-08-23 20:39:02 |
合計ジャッジ時間 | 14,476 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 69 ms
71,144 KB |
testcase_01 | AC | 72 ms
71,264 KB |
testcase_02 | AC | 77 ms
75,480 KB |
testcase_03 | AC | 79 ms
75,740 KB |
testcase_04 | AC | 71 ms
71,292 KB |
testcase_05 | AC | 80 ms
75,776 KB |
testcase_06 | AC | 73 ms
71,288 KB |
testcase_07 | AC | 83 ms
76,184 KB |
testcase_08 | AC | 594 ms
125,304 KB |
testcase_09 | AC | 530 ms
129,100 KB |
testcase_10 | AC | 626 ms
118,192 KB |
testcase_11 | AC | 615 ms
127,020 KB |
testcase_12 | AC | 524 ms
112,440 KB |
testcase_13 | AC | 647 ms
134,168 KB |
testcase_14 | AC | 493 ms
108,448 KB |
testcase_15 | AC | 447 ms
111,048 KB |
testcase_16 | AC | 684 ms
134,448 KB |
testcase_17 | AC | 611 ms
133,968 KB |
testcase_18 | AC | 405 ms
104,868 KB |
testcase_19 | AC | 667 ms
133,920 KB |
testcase_20 | AC | 687 ms
134,132 KB |
testcase_21 | AC | 588 ms
134,548 KB |
testcase_22 | AC | 683 ms
134,076 KB |
testcase_23 | AC | 587 ms
135,208 KB |
testcase_24 | AC | 608 ms
134,560 KB |
testcase_25 | AC | 657 ms
134,008 KB |
testcase_26 | AC | 71 ms
71,020 KB |
testcase_27 | AC | 574 ms
134,476 KB |
testcase_28 | AC | 467 ms
134,464 KB |
ソースコード
import sys input=lambda:sys.stdin.readline().rstrip() class unionFind: def __init__(self,N): self.N=N self.parent=[-1 for i in range(N)] self.size=[1 for i in range(N)] def find(self,x): path=[x] while self.parent[path[-1]]!=-1: path.append(self.parent[path[-1]]) for i in path[:-1]: self.parent[i]=path[-1] return path[-1] def unite(self,x,y): roots=sorted([self.find(x),self.find(y)],key=lambda _:self.parent[_]) if roots[0]!=roots[1]: self.parent[roots[0]]=roots[1] self.size[roots[1]]+=self.size[roots[0]] N,M=map(int,input().split()) A=[list(map(lambda x:int(x)-1,input().split())) for i in range(M)][::-1] U=unionFind(N) mem={} for i in range(N): mem[U.find(i)]=0 for i in A: temp=max(mem[U.find(i[0])],mem[U.find(i[1])])+1 U.unite(i[0],i[1]) mem[U.find(i[0])]=temp print(max(mem.values()))