結果
問題 | No.2642 Don't cut line! |
ユーザー | hato336 |
提出日時 | 2024-02-19 22:23:50 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,263 bytes |
コンパイル時間 | 173 ms |
コンパイル使用メモリ | 82,312 KB |
実行使用メモリ | 166,984 KB |
最終ジャッジ日時 | 2024-09-29 02:17:34 |
合計ジャッジ時間 | 21,832 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 114 ms
89,132 KB |
testcase_01 | AC | 801 ms
166,516 KB |
testcase_02 | AC | 806 ms
166,216 KB |
testcase_03 | AC | 858 ms
166,984 KB |
testcase_04 | AC | 839 ms
165,956 KB |
testcase_05 | AC | 810 ms
166,604 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 489 ms
122,436 KB |
testcase_17 | AC | 758 ms
156,548 KB |
testcase_18 | AC | 810 ms
160,092 KB |
testcase_19 | AC | 633 ms
139,384 KB |
testcase_20 | AC | 623 ms
121,280 KB |
testcase_21 | AC | 402 ms
112,408 KB |
testcase_22 | AC | 403 ms
113,772 KB |
testcase_23 | AC | 918 ms
166,856 KB |
testcase_24 | AC | 598 ms
127,568 KB |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 645 ms
138,504 KB |
testcase_28 | AC | 875 ms
158,072 KB |
testcase_29 | WA | - |
testcase_30 | AC | 616 ms
122,368 KB |
testcase_31 | AC | 768 ms
149,136 KB |
testcase_32 | AC | 625 ms
120,888 KB |
testcase_33 | AC | 117 ms
89,112 KB |
testcase_34 | AC | 123 ms
89,052 KB |
testcase_35 | AC | 125 ms
89,344 KB |
ソースコード
import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random class lca(): def __init__(self,n,edge): self.n = n self.edge = edge self.dist = [10**20] * n self.k = math.floor(math.log2(n)) self.ansestor = [[-1 for i in range(n)] for j in range(self.k + 1)] self.mini = [[-10**18 for i in range(n)] for j in range(self.k + 1)] self.bfs() for i in range(self.k): for j in range(n): if self.ansestor[i][j] == -1: self.ansestor[i+1][j] = -1 else: self.ansestor[i+1][j] = self.ansestor[i][self.ansestor[i][j]] for i in range(self.k): for j in range(n): self.mini[i+1][j] = max(self.mini[i+1][j],self.mini[i][j],self.mini[i][self.ansestor[i][j]]) def bfs(self): d = collections.deque() d.append(0) mou = set() mou.add(0) self.dist[0] = 0 while d: now = d.popleft() for i,j in self.edge[now]: if i not in mou: self.ansestor[0][i] = now self.mini[0][i] = j d.append(i) mou.add(i) self.dist[i] = self.dist[now] + 1 def ans(self,u,a): for i in reversed(range(self.k + 1)): if u == -1: break if (a >> i) & 1: u = self.ansestor[i][u] return u def ans2(self,u,a): res = -10**18 for i in reversed(range(self.k + 1)): if u == -1: break if (a >> i) & 1: res = max(res,self.mini[i][u]) u = self.ansestor[i][u] return res def calc(self,s,t): if self.dist[s] > self.dist[t]: s = self.ans(s,self.dist[s] - self.dist[t]) if self.dist[s] < self.dist[t]: t = self.ans(t,-self.dist[s] + self.dist[t]) for i in reversed(range(self.k)): ns = self.ansestor[i][s] nt = self.ansestor[i][t] if ns != nt: s = ns t = nt x = (0 if self.ansestor[0][s] == -1 else s if s == t else self.ansestor[0][s]) return x class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = collections.defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return ''.join(f'{r}: {m}' for r, m in self.all_group_members().items()) #sys.setrecursionlimit(10**9) #sys.set_int_max_str_digits(0) input = sys.stdin.readline n,k,c = map(int,input().split()) edge = [[] for i in range(n)] e = [] for i in range(k): u,v,w,p = map(int,input().split()) u-=1 v-=1 edge[u].append((v,w)) edge[v].append((u,w)) e.append((p,w,u,v)) uf = UnionFind(n) e.sort(key=lambda x:x[1]) ans = 0 temp = 0 for p,w,u,v in e: if uf.same(u,v) == False: ans += w uf.union(u,v) if ans > c: exit(print(-1)) l = lca(n,edge) for p,w,u,v in e: x = l.calc(u,v) if ans - max(l.ans2(u,l.dist[u]-l.dist[x]),l.ans2(v,l.dist[v]-l.dist[x])) + w <= c: temp = max(temp,p) print(temp)