結果
問題 | No.317 辺の追加 |
ユーザー | mkawa2 |
提出日時 | 2023-03-16 11:57:01 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,403 bytes |
コンパイル時間 | 356 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 92,460 KB |
最終ジャッジ日時 | 2024-09-18 09:17:52 |
合計ジャッジ時間 | 16,592 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
59,264 KB |
testcase_01 | AC | 42 ms
54,228 KB |
testcase_02 | AC | 366 ms
85,428 KB |
testcase_03 | AC | 280 ms
83,372 KB |
testcase_04 | AC | 652 ms
88,428 KB |
testcase_05 | AC | 209 ms
80,640 KB |
testcase_06 | AC | 262 ms
82,652 KB |
testcase_07 | AC | 163 ms
78,552 KB |
testcase_08 | AC | 1,294 ms
92,460 KB |
testcase_09 | AC | 473 ms
88,280 KB |
testcase_10 | AC | 393 ms
86,400 KB |
testcase_11 | AC | 296 ms
89,148 KB |
testcase_12 | AC | 344 ms
85,656 KB |
testcase_13 | AC | 408 ms
89,452 KB |
testcase_14 | AC | 377 ms
87,848 KB |
testcase_15 | AC | 363 ms
86,472 KB |
testcase_16 | AC | 567 ms
89,252 KB |
testcase_17 | AC | 357 ms
86,856 KB |
testcase_18 | AC | 369 ms
85,796 KB |
testcase_19 | AC | 339 ms
85,760 KB |
testcase_20 | AC | 705 ms
87,960 KB |
testcase_21 | AC | 200 ms
79,616 KB |
testcase_22 | AC | 185 ms
79,212 KB |
testcase_23 | AC | 225 ms
79,860 KB |
testcase_24 | AC | 238 ms
81,920 KB |
testcase_25 | AC | 225 ms
80,880 KB |
testcase_26 | AC | 235 ms
81,172 KB |
testcase_27 | AC | 238 ms
80,748 KB |
testcase_28 | AC | 339 ms
81,360 KB |
testcase_29 | AC | 120 ms
77,312 KB |
testcase_30 | TLE | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 md = 10**9+7 # md = 998244353 from collections import Counter, deque class UnionFind: def __init__(self, n): self.state = [-1]*n self.size_table = [1]*n self.cnt = n def root(self, u): stack = [] while self.state[u] >= 0: stack.append(u) u = self.state[u] for v in stack: self.state[v] = u return u def same(self, u, v): return self.root(u) == self.root(v) def merge(self, u, v): u = self.root(u) v = self.root(v) if u == v: return False du = -self.state[u] dv = -self.state[v] if du < dv: u, v = v, u if du == dv: self.state[u] -= 1 self.state[v] = u self.cnt -= 1 self.size_table[u] += self.size_table[v] return True def size(self, u): return self.size_table[self.root(u)] n, m = LI() uf = UnionFind(n) for _ in range(m): u, v = LI1() uf.merge(u, v) seen = set() cnt = Counter() for u in range(n): r = uf.root(u) if r in seen: continue seen.add(r) cnt[uf.size(r)] += 1 # pDB(cnt) def push(i): val = dp[i]*s-i while mns and mns[-1][-1] >= val: mns.pop() mns.append((i, val)) dp = [-1]+[inf]*n for s, c in cnt.items(): for si in range(s): mns = deque() for k in range(c-1): j = n-si-s*(k+1) if j < 0 or dp[j] == inf: continue push(j) for i in range(n-si, s-2, -s): while mns and mns[0][0] > i-s: mns.popleft() if i-s*c >= 0: push(i-s*c) if mns: dp[i] = min(dp[i], (mns[0][1]+i)//s) for i in range(n): if dp[i] == inf: dp[i] = -1 print(*dp[1:], sep="\n")