結果
| 問題 | No.1194 Replace |
| コンテスト | |
| ユーザー |
37zigen
|
| 提出日時 | 2020-08-31 18:19:26 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 1,465 ms / 2,000 ms |
| コード長 | 481 bytes |
| コンパイル時間 | 120 ms |
| コンパイル使用メモリ | 12,416 KB |
| 実行使用メモリ | 76,428 KB |
| 最終ジャッジ日時 | 2024-11-16 19:55:16 |
| 合計ジャッジ時間 | 28,372 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
import sys
sys.setrecursionlimit(10**6)
N,M=map(int,input().split())
g=dict()
e=[]
for i in range(M):
b,c=map(int,input().split())
e.append((c,b))
g[c]=[]
for a,b in e:
g[a].append(b)
e.sort(reverse=True)
to=dict()
ans=N*(N+1)//2
def dfs(cur,v):
global ans
for dst in g[cur]:
if dst in to or dst>v:
continue
to[dst]=v
ans+=v-dst
if dst in g:
dfs(dst,v)
for src,tmp in e:
dfs(src,src)
print(ans)
37zigen