結果
| 問題 | No.2642 Don't cut line! |
| コンテスト | |
| ユーザー |
ニックネーム
|
| 提出日時 | 2024-02-19 23:10:03 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 851 bytes |
| 記録 | |
| コンパイル時間 | 423 ms |
| コンパイル使用メモリ | 82,332 KB |
| 実行使用メモリ | 107,776 KB |
| 最終ジャッジ日時 | 2024-09-29 02:50:52 |
| 合計ジャッジ時間 | 19,429 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 WA * 7 |
ソースコード
class UF:
def __init__(self,n):
self.p = [-1]*n
def f(self,x):
if self.p[x]<0: return x
else: self.p[x] = self.f(self.p[x]); return self.p[x]
def u(self,x,y):
x = self.f(x); y = self.f(y)
if x==y: return
if -self.p[x]<-self.p[y]: x,y = y,x
self.p[x] += self.p[y]; self.p[y] = x
def s(self,x,y): return self.f(x) == self.f(y)
n,k,c = map(int,input().split())
wpuv = []
for _ in range(k):
u,v,w,p = map(int,input().split())
wpuv.append((w,p,u-1,v-1))
uf = UF(n); adj = [[] for _ in range(n)]; d = m = 0
for w,p,u,v in sorted(wpuv):
if not uf.s(u,v):
uf.u(u,v); d += w; m = max(m,p)
adj[u-1].append(w); adj[v-1].append(w)
e = [max(adj[i]) for i in range(n)]
if d>c: exit(print(-1))
for w,p,u,v in wpuv:
if d-max(e[u],e[v])+w<=c: m = max(m,p)
print(m)
ニックネーム