結果
| 問題 |
No.2915 辺更新価値最大化
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2024-11-02 03:18:28 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 932 ms / 2,000 ms |
| コード長 | 1,065 bytes |
| コンパイル時間 | 366 ms |
| コンパイル使用メモリ | 82,516 KB |
| 実行使用メモリ | 88,048 KB |
| 最終ジャッジ日時 | 2024-11-02 03:18:41 |
| 合計ジャッジ時間 | 11,731 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
ソースコード
import sys
input = sys.stdin.readline
from heapq import heappop,heappush
N,M,C=map(int,input().split())
EDGE=[list(map(int,input().split())) for i in range(M)]
for i in range(M):
EDGE[i][0]-=1
EDGE[i][1]-=1
P=[1<<63]*N
P[0]=0
for i in range(N+10):
for x,y,w in EDGE:
if P[y]>P[x]-w:
P[y]=P[x]-w
Q=list(map(int,input().split()))
for i in range(C):
Q[i]-=1
USE=[1]*M
for q in Q:
USE[q]^=1
DP=[1<<63]*N
DP[0]=0
E=[[] for i in range(N)]
for i in range(M):
if USE[i]==0:
E[x].append((y,1<<63))
continue
x,y,dis=EDGE[i]
E[x].append((y,-dis))
Q=[(0,0)]
while Q:
now,ind=heappop(Q)
if DP[ind]!=now:
continue
for to,w in E[ind]:
if DP[to]>DP[ind]+w+P[ind]-P[to]:
DP[to]=DP[ind]+w+P[ind]-P[to]
heappush(Q,(DP[to],to))
ANS=DP[-1]+P[-1]
if ANS>1000000000:
print("NaN")
else:
print(-ANS)
titia