結果
| 問題 | No.1194 Replace |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-12-13 09:11:13 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 555 bytes |
| 記録 | |
| コンパイル時間 | 248 ms |
| コンパイル使用メモリ | 82,248 KB |
| 実行使用メモリ | 199,476 KB |
| 最終ジャッジ日時 | 2024-07-22 04:20:22 |
| 合計ジャッジ時間 | 12,189 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 WA * 21 |
ソースコード
import sys
input = sys.stdin.buffer.readline
N, M = map(int, input().split())
BC = [tuple(map(int, input().split())) for _ in range(M)]
nodes = set()
for b, c in BC:
nodes.add(b)
nodes.add(c)
nodes = sorted(nodes)
comp = {x: i for i, x in enumerate(nodes)}
L = len(comp)
G = [[] for _ in range(L)]
for b, c in BC:
G[comp[c]].append(comp[b])
table = nodes.copy()
for i in range(L - 1, -1, -1):
x = table[i]
for j in G[i]:
if table[j] < x:
table[j] = x
ans = N * (N + 1) // 2 - sum(nodes) + sum(table)
print(ans)