結果

問題 No.1502 Many Simple Additions
ユーザー googol_S0googol_S0
提出日時 2021-05-07 22:08:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 550 ms / 2,000 ms
コード長 1,654 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 135,916 KB
最終ジャッジ日時 2023-10-13 22:28:29
合計ジャッジ時間 10,085 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,532 KB
testcase_01 AC 93 ms
71,384 KB
testcase_02 AC 91 ms
71,636 KB
testcase_03 AC 91 ms
71,504 KB
testcase_04 AC 88 ms
71,600 KB
testcase_05 AC 91 ms
71,504 KB
testcase_06 AC 90 ms
71,340 KB
testcase_07 AC 92 ms
71,764 KB
testcase_08 AC 92 ms
71,712 KB
testcase_09 AC 91 ms
71,384 KB
testcase_10 AC 92 ms
71,656 KB
testcase_11 AC 90 ms
71,344 KB
testcase_12 AC 91 ms
71,328 KB
testcase_13 AC 92 ms
71,388 KB
testcase_14 AC 91 ms
71,856 KB
testcase_15 AC 90 ms
71,524 KB
testcase_16 AC 89 ms
71,504 KB
testcase_17 AC 88 ms
71,836 KB
testcase_18 AC 89 ms
71,340 KB
testcase_19 AC 88 ms
71,728 KB
testcase_20 AC 88 ms
71,472 KB
testcase_21 AC 85 ms
71,344 KB
testcase_22 AC 86 ms
71,600 KB
testcase_23 AC 86 ms
71,760 KB
testcase_24 AC 87 ms
71,628 KB
testcase_25 AC 87 ms
71,384 KB
testcase_26 AC 86 ms
71,628 KB
testcase_27 AC 248 ms
98,920 KB
testcase_28 AC 257 ms
99,468 KB
testcase_29 AC 157 ms
86,672 KB
testcase_30 AC 517 ms
135,916 KB
testcase_31 AC 525 ms
134,808 KB
testcase_32 AC 550 ms
127,964 KB
testcase_33 AC 369 ms
117,032 KB
testcase_34 AC 374 ms
120,928 KB
testcase_35 AC 409 ms
117,392 KB
testcase_36 AC 218 ms
112,840 KB
testcase_37 AC 217 ms
112,740 KB
testcase_38 AC 353 ms
114,424 KB
testcase_39 AC 238 ms
103,216 KB
testcase_40 AC 243 ms
85,960 KB
testcase_41 AC 181 ms
81,764 KB
testcase_42 AC 475 ms
122,788 KB
testcase_43 AC 88 ms
71,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
N,M,K=map(int,input().split())
G=[[] for i in range(N)]
for i in range(M):
  x,y,z=map(int,input().split())
  x-=1
  y-=1
  G[x].append((y,z))
  G[y].append((x,z))
A=[]
ANS=1
ANS2=1
mod=10**9+7
F=[0]*N
X=[]
Y=[[] for i in range(N)]
V=K-1
from collections import *
INF=10**17
for i in range(N):
  if F[i]:
    continue
  for j in range(len(X)-1,-1,-1):
    Y[X[j]].clear()
    del X[j]
  Q=deque([(i,(1,0))])
  while len(Q):
    for _ in range(len(Q)):
      v=Q.popleft()
      X.append(v[0])
      F[v[0]]=1
      Y[v[0]].append(v[1])
      for j in range(len(G[v[0]])-1,-1,-1):
        Q.append((G[v[0]][j][0],(-v[1][0],G[v[0]][j][1]-v[1][1])))
        del G[v[0]][j]
  X=list(set(X))
  L,R=1,K
  L2,R2=1,V
  for j in range(len(X)):
    j=X[j]
    Z=[INF,INF]
    for k in range(len(Y[j])):
      if Y[j][k][0]==1:
        if Z[0]==INF:
          Z[0]=Y[j][k][1]
        else:
          if Z[0]!=Y[j][k][1]:
            L=K+1
            L2=K
      else:
        if Z[1]==INF:
          Z[1]=Y[j][k][1]
        else:
          if Z[1]!=Y[j][k][1]:
            L=K+1
            L2=K
    if Z[0]<INF and Z[1]<INF:
      if (Z[0]^Z[1])&1:
        L=K+1
        L2=K
      else:
        x=(Z[1]-Z[0])>>1
        L=max(L,x)
        L2=max(L2,x)
        R=min(R,x)
        R2=min(R2,x)
    if Z[0]<INF:
      R=min(R,K-Z[0])
      R2=min(R2,V-Z[0])
      L=max(L,-Z[0]+1)
      L2=max(L2,-Z[0]+1)
    if Z[1]<INF:
      R=min(R,Z[1]-1)
      R2=min(R2,Z[1]-1)
      L=max(L,Z[1]-K)
      L2=max(L2,Z[1]-V)
  ANS=ANS*max(0,R-L+1)%mod
  ANS2=ANS2*max(0,R2-L2+1)%mod
print((ANS-ANS2)%mod)
0