結果
| 問題 |
No.1523 +/- Tree
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 13:23:56 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 932 bytes |
| コンパイル時間 | 194 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 70,208 KB |
| 最終ジャッジ日時 | 2025-06-12 13:29:38 |
| 合計ジャッジ時間 | 7,142 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 15 WA * 29 |
ソースコード
n, k = map(int, input().split())
if k == 1 or k == n - 1:
print("No")
else:
print("Yes")
edges = []
# Construct a chain with a negative edge in the middle
# Middle edge is at position k, with value -(k+1)
# Other edges are 1
# This works for the sample case and similar configurations
for i in range(1, n):
if i == k:
edges.append((i, i+1, -(k + 1)))
else:
edges.append((i, i+1, 1))
# Check if the total sum is positive
total = sum(w for u, v, w in edges)
if total <= 0:
# Adjust the first and last edges to ensure total sum is positive
# For example, set them to 2 instead of 1
edges = []
for i in range(1, n):
if i == k:
edges.append((i, i+1, -(k + 1)))
else:
edges.append((i, i+1, 2))
# Output the edges
for u, v, w in edges:
print(u, v, w)
gew1fw