結果
| 問題 | 
                            No.1194 Replace
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-08-31 18:17:53 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 441 bytes | 
| コンパイル時間 | 87 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 76,476 KB | 
| 最終ジャッジ日時 | 2024-11-16 19:51:21 | 
| 合計ジャッジ時間 | 26,669 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 11 RE * 16 | 
ソースコード
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)